Fork me on GitHub
#clj-kondo
<
2022-01-25
>
JR00:01:23

I found https://www.braveclojure.com/writing-macros/

(ns macro-test.core)


(defn criticize-code [criticism code]
  `(println ~criticism (quote ~code)))

(defmacro code-critic
  [good bad]
  `(do ~@(map #(apply criticize-code %)
              [["this is bad code: " bad]
               ["this is good code: " good]])))

(code-critic (1 + 1) (+ 1 1))     

clj-kondo  --lint /tmp/macro_test/src/macro_test/core.clj
/private/tmp/macro_test/src/macro_test/core.clj:13:14: error: a number is not a function
linting took 13ms, errors: 1, warnings: 0
clj-kondo highlights the (1 +1) part as an error. From my very limited understand of macros, (1 + 1) should be ignored since itโ€™s in a syntax quote. Is this the sort of thing Iโ€™d have to fix with a hook?

borkdude09:01:54

@john.t.richardson.dev That's the sort of thing you could fix with a hook, but there are other options as well

dharrigan10:01:03

At work we use (for better or worse) timbre as a logging library. I notice in impl/analyzer.clj there are is a check at lines 2033-2039 for analyzing clojure.tools.logging infof debugf etc., Considering that timbre is a popular library for logging, would you be open to a PR that also adds taoensso.timbre/infof debugf etc... for those to be included in analysis?

borkdude10:01:33

I'd like to support this via hooks if possible. The built-in support for many libraries came from a time when hooks didn't exist yet.

dharrigan10:01:08

Ah yes, of course, since you would have to bring in the dep, right? in deps.edn

borkdude10:01:31

Hooks don't need the dep, but I think it's better if support for libraries are built using hooks, since they can evolve independently from the installed clj-kondo version and can be maintained by others than me as well

borkdude10:01:20

Perhaps for now you could also use :lint-as for those macros

borkdude10:01:28

if the syntax is similar

dharrigan10:01:41

Yes, very similar and yup easy enough to add that ๐Ÿ™‚

dharrigan10:01:54

Also, doing a hook might be fun little thing to do eventually in my spare time ๐Ÿ™‚

borkdude10:01:15

If it can be done using :lint-as that would be my preference

borkdude10:01:41

hooks are cool, but usually only needed for macros that have a non-standard syntax compared to core ones

dharrigan10:01:45

yes, that sounds best

dharrigan10:01:49

just trying it out

dharrigan10:01:52

Yup, works grand