clj-kondo

imre 2025-01-21T10:37:25.221189Z

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?

imre 2025-01-21T10:37:33.226329Z

; 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

imre 2025-01-21T10:38:02.203339Z

here are the contents a bit more readable

imre 2025-01-21T10:39:04.762449Z

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

imre 2025-01-21T10:44:09.677039Z

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

borkdude 2025-01-21T10:44:32.294919Z

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 []")

imre 2025-01-21T10:44:41.204419Z

ah

borkdude 2025-01-21T10:45:13.331929Z

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

borkdude 2025-01-21T10:45:22.720309Z

in combination with a macro expand hook

borkdude 2025-01-21T10:45:31.657749Z

since that uses sexpr internally

imre 2025-01-21T10:45:41.943019Z

gotcha, thank you

imre 2025-01-21T10:47:06.117969Z

this should help reducing it even further

imre 2025-01-21T10:47:11.960979Z

I'll submit an issue

imre 2025-01-21T11:04:47.425589Z

Thank you!

imre 2025-01-21T16:12:59.725309Z

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
imre 2025-01-23T17:06:36.963419Z

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
imre 2025-01-21T16:15:01.081289Z

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

imre 2025-01-21T16:16:51.838689Z

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

borkdude 2025-01-21T16:18:48.181119Z

could be one of the commits on dec. 3

borkdude 2025-01-21T16:18:54.195819Z

not sure of course, but worth a try

imre 2025-01-21T16:20:07.085809Z

thanks I'll try to check that out