clj-kondo 2025-01-21

Hey folks. I'm getting a strange warning when using discouraging read-string in combination with a macroexpanded do-template. Any ideas why it's happening?

; echo '(ns foo (:require bar clojure.template)) (clojure.template/do-template [x] (do x #bar/a "aaa") (bar/b "bbb"))' | clj-kondo --config '{:linters {:discouraged-var {clojure.core/read-string {}}} :hooks {:macroexpand {clojure.template/do-template clojure.template/do-template}}}' --lint -
<stdin>:1:96: warning: Discouraged var: clojure.core/read-string
linting took 86ms, errors: 0, warnings: 1

here are the contents a bit more readable

(ns foo (:require bar clojure.template))

(clojure.template/do-template
 [x]
 (do x #bar/a "aaa")
 (bar/b "bbb"))
and
{:linters
 {:discouraged-var {clojure.core/read-string {}}}
 :hooks
 {:macroexpand {clojure.template/do-template clojure.template/do-template}}}

do-template doesn't contain any read-strings as far as I can tell and the rest are made up

I don't think this is related to do-template at all but something in rewrite-clj

user=> (rewrite-clj.node/sexpr (p/parse-string "#bar/x []"))
(read-string "#bar/x []")

feel free to report this (small repro I posted is fine) as a false positive with discouraged-var

in combination with a macro expand hook

since that uses sexpr internally

gotcha, thank you

this should help reducing it even further

I'll submit an issue

I'm seeing some of our hooks not working when switching from 2024.11.14 to 2025.01.16, and we're now getting some unresolved symbol errors. Any ideas what might be causing this? I'm trying to review the changelog to see if I can find it.

👀 1

I tried but haven't been able to repro the old behavior even going back several months. Concluded that the hook must be incorrect and since it was also quite limited, I ended up rewriting it. Works well now 🙂

🎉 1

Of course it's possible that our hook does something fishy

Not sure how much of the hook code I can share, but there's one part that alters a node adding some metadata to parts of it:

(vary-meta expected-fn assoc :clj-kondo/ignore [:unresolved-symbol])

could be one of the commits on dec. 3

not sure of course, but worth a try

thanks I'll try to check that out