This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-15
Channels
- # announcements (1)
- # babashka (21)
- # beginners (23)
- # biff (8)
- # boot (1)
- # cider (4)
- # clerk (21)
- # clj-kondo (31)
- # clojure (60)
- # clojure-brasil (5)
- # clojure-europe (20)
- # clojurescript (21)
- # datomic (14)
- # graalvm (10)
- # honeysql (1)
- # hoplon (4)
- # hyperfiddle (42)
- # introduce-yourself (1)
- # leiningen (1)
- # lsp (53)
- # pathom (4)
- # releases (2)
- # scittle (24)
- # shadow-cljs (3)
- # xtdb (4)
Is there any way to have a hook treat a namespace as required? I am working on writing a hook for a macro that expands into a call to clojure.core.match/match
- I would like the expansion to be linted by clj-kondo
- The consuming namespaces don't require clojure.core.match
directly (instead the macroexpansion resolves it) causing clj-kondo to hit an :unresolved-namespace
error. If the consuming namespace requires clojure.core.match
everything works correctly.
Hmm yes. this issue has come up a few times now. What you can do is this:
:config-in-call {your-ns/your-macro {:unresolved-namespace {:exclude [clojure.core.match]}}}
Nice, thank you! Is there any way to apply this to metadata on the node returned from the hook instead? (ie. similar to how you can add metadata for :clj-kondo/ignore
)
currently not yet, but you can do this in your macro:
(defmacro my-macro
{:clj-kondo/config '{:linters {:unresolved-namespace ...}}}
[ ])
after linting that macro, the config applies to calls to that macro
this should work in clj-kondo from a month agoHmmm, the :config-in-call
doesn't seem to be working. I will try the annotation on the macro directly. Wondering if it's because of an interaction between :analyze-call
and :config-in-call
The metadata annotation did work correctly, but it's worth noting that because the require didn't happen, the analysis for nevermind, looks to be workingclojure.core.match
did not get applied (eg. a warning on an unused variable) -
the annotation on the macro has the same effect as config-in-call so maybe you just made a mistake in config-in-call
if you look in .clj-kondo/_inlined-configs
or so you will see what config it expanded to
Checking the .clj-kondo/_inlined-configs
- should that be a file? Trying to access it but doesn't look to exist
The config-in-call
was me copy pasting:
:config-in-call {your-ns/your-macro {:unresolved-namespace {:exclude [clojure.core.match]}}}
Needed to be
:config-in-call {your-ns/your-macro {:linters {:unresolved-namespace {:exclude [clojure.core.match]}}}}
The metadata / config-in-call works 🙂 Thank you a ton for the help
It does indeed 🙂
(defmacro when-match
"Similar to `when-let` but uses match patterns for binding."
{:clj-kondo/config '{:linters {:unresolved-namespace {:exclude [clojure.core.match]}}}}
[bindings & body]
(let [[pattern expr] bindings]
`(match ~expr
~pattern (do ~@body)
_# nil)))
Just a simple little thing, but pretty useful. Extra useful w/ clj-kondo linting 🥳 - Thank you again for the help and everything you do for the clojure community 🙏
Ahhh! The clojure.core.match analysis actually doesn't work 😞 I had a lingering require
(So it's giving unresolved variable warnings as written). Any way to tricking into resolving the symbol?
ah, that's a shame. I think we should fix this in clj-kondo, to treat an excluded namespace as if it were already required. can you post an issue about that?
Yep, will do!
I don't think there's a good workaround for it now, unless maybe you generate
(do (require 'clojure.core.match) (when-let ...))
not sure if that's going to work, I don't think it willUnfortunately it doesn't work unless the macro is called in the root of the namespace (ie. it won't work on code inside a defn
)
https://github.com/clj-kondo/clj-kondo/issues/2051 Thanks again for the responses and help 🙂