clj-kondo

https://github.com/clj-kondo/clj-kondo
Karol Wójcik 2020-12-14T10:57:03.131400Z

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.

borkdude 2020-12-14T11:01:15.132100Z

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

borkdude 2020-12-14T11:05:26.133600Z

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

juhoteperi 2020-12-14T11:07:28.134900Z

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?

juhoteperi 2020-12-14T11:09:11.135700Z

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

borkdude 2020-12-14T11:10:25.136400Z

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ójcik 2020-12-14T11:13:44.138500Z

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

juhoteperi 2020-12-14T11:14:00.138800Z

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

borkdude 2020-12-14T11:15:23.139200Z

@juhoteperi You should use --config

juhoteperi 2020-12-14T11:16:14.139600Z

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

👍 1
borkdude 2020-12-14T11:17:44.140200Z

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

👍 1
1
🎉 1
Karol Wójcik 2020-12-14T11:19:33.141Z

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