Fork me on GitHub
#clj-kondo
<
2020-12-14
>
Karol Wójcik10:12:03

Is it possible to not show specific warning of custom macro? For instance I got the macro like

(defmacro in-node
  [& body]
  `(when config.core/NODEJS?
     ~@body))
which is lint-as in config.edn in the following manner:
core.isomorphic/in-node      clojure.core/do
I would like this macro to not dispatch warning about redundant do.

borkdude11:12:15

Maybe :lint-as clojure.core/when works? (lucky guess)

borkdude11:12:26

or clojure.core/fn maybe, something which receives a body but which is not do ;)

juhoteperi11:12:28

I kind of remember looking at this, but maybe I confuse this with lint-as clojure.core/for giving "redundant let" warnings. But kind of same thing maybe?

juhoteperi11:12:11

I think analyze-let-like-bindings has some additional checks to differentiate calls to clojure.core macros and lint-as macros? https://github.com/borkdude/clj-kondo/commit/3e138713b6183f7faca74af8f0aa2b1b0486a1ac

borkdude11:12:25

true, we could do the same for do if that isn't the case already. An alternative would be to write a small hook. Redundant let + do is ignored from generated hook code

Karol Wójcik11:12:44

Although all proposals. Altough those remove the redundant do warning they introduce new ones.

juhoteperi11:12:00

Not sure how to reproduce this, simple case seems to work:

❯ clj-kondo -c '{:lint-as {user/foo clojure.core/do}}' --lint -
(ns user)

(defmacro foo [& body] (when 2 ~@body))

(foo 1)
linting took 8742ms, errors: 0, warnings: 0

borkdude11:12:23

@juhoteperi You should use --config

juhoteperi11:12:14

Oops, also forgot backtick from the macro.

❯ clj-kondo --config '{:lint-as {user/foo clojure.core/do}}' --lint -
(ns user)

(defmacro foo [& body] `(when 2 ~@body))

(foo 1)
<stdin>:5:1: warning: redundant do
linting took 4304ms, errors: 0, warnings: 1

👍 3
borkdude11:12:44

@karol.wojcik Why do you need :lint-as at all? If you just pass a body to that macro, I don't think you would get false positives? (it could very well be, I'm not awake enough yet)

3
🎉 3
👍 3
Karol Wójcik11:12:33

@borkdude you are right 😄 Thank you so much guys @juhoteperi @borkdude