Fork me on GitHub
#clj-kondo
<
2020-11-14
>
lvh21:11:49

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

lvh21:11:33

(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)

borkdude21:11:49

@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 .

borkdude21:11:54

The hook code for this macro would be pretty straightforward.

borkdude21:11:29

@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))}))

lvh21:11:14

Awesome, thanks!

lvh21:11:08

It's internal so I think I'll just change the API to take varargs and lint it like declare

lvh21:11:10

much appreciated!

👍 3
didibus23:11:57

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?

borkdude11:11:10

This isn't possible using lint-as. I think you would need to write a hook to support this