Is it possible to teach clj-kondo that a particular macro defines many names, and so those names are no longer undefined (without declare
), e.g. : https://github.com/lvh/caesium/pull/74/files#diff-65e89161949c41707e1727f4a784969c02b9626b37ac949f704efcd26f7a9519R6
(as specified in that PR, it works: clj-kondo doesn't complain, because there's a declare
, I'm asking if there's a magic configuration incantation that makes it unnecessary)
@lvh if the macro is syntactically similar to a core one, then you can :lint-as
but for this macro that doesn't apply. E.g. if defconsts
was varargs like declare
then :lint-as
with clojure.core/declare
would work.
The other way is to write a hook to rewrite your function call to multiple top-level defs
or just declare
.
The hook code for this macro would be pretty straightforward.
@lvh This works:
borkdude@MBP2019 /tmp $ cat foo.clj
(require '[foo.bar :as b])
(b/defconst [a b c])
a
b
c
borkdude@MBP2019 /tmp $ cat .clj-kondo/config.edn
{:hooks {:analyze-call {foo.bar/defconst hooks.defconst/defconst}} }
borkdude@MBP2019 /tmp $ cat .clj-kondo/hooks/defconst.clj
(ns hooks.defconst
(:require [clj-kondo.hooks-api :as api]))
(defn defconst [{:keys [:node]}]
(let [[_ vector-node] (:children node)
const-nodes (:children vector-node)
new-node (api/list-node (list* (api/token-node 'declare)
const-nodes))]
{:node (with-meta new-node
(meta node))}))
Awesome, thanks!
It's internal so I think I'll just change the API to take varargs and lint it like declare
much appreciated!
I have an overloaded function, it has a 1-ary and a 2-ary version. I need to specify a :lint-as
that is different for each. Is that something that clj-kondo support?
This isn't possible using lint-as. I think you would need to write a hook to support this
Cool, thx