clj-kondo

https://github.com/clj-kondo/clj-kondo
lvh 2020-11-14T21:05:49.459900Z

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

lvh 2020-11-14T21:06:33.460600Z

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

borkdude 2020-11-14T21:12:49.462500Z

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

borkdude 2020-11-14T21:13:54.463Z

The hook code for this macro would be pretty straightforward.

borkdude 2020-11-14T21:20:29.463200Z

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

lvh 2020-11-14T21:44:14.463500Z

Awesome, thanks!

lvh 2020-11-14T21:45:08.463900Z

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

lvh 2020-11-14T21:45:10.464200Z

much appreciated!

👍 1
2020-11-14T23:50:57.465300Z

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?

borkdude 2020-11-15T11:38:10.465400Z

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

2020-11-16T23:27:55.465600Z

Cool, thx