I'm writing a hook that partially expands the macro it analyzes. Part of the expansion is the addition of a call to clojure.core.match/match, which the original macro uses internally. When I add that call as a list-node, I get a missing require warning. Is there a way to avoid that?
Looks like I can just add metadata to ignore that warning:
(-> (api/token-node 'clojure.core.match/match)
(vary-meta update :clj-kondo/ignore conj :unresolved-namespace))awesome :)
hmm, I can't seem to get proper linting on clojure.core.match/match for some reason though, not even outside of this custom macro... must be doing something wrong
anyway, it's late on a Friday evening so I'll deal with this another time
Looks like using metadata is an implementation detail. https://github.com/clj-kondo/clj-kondo/issues/2490#issuecomment-2671414913
that's another way of using metadata though
But I don't want to do that, because I want clj-kondo to analyze the call to core.match/match
Userspace code would look like this:
(mymacro [1 2 3] body)
And mimicking what mymacro does but with simplifications, I want the above to be analyzed as
(fn [& args] (clojure.core.match/match [args] [1 2 3] body))
I could write a macroexpand hook for this, but I can't because I also want to do custom analysis on the usage of mymacro and there's no way to use both analyze-call and macroexpand for the same macro
So what I need to do is turn mymacro into a match as if clojure.core.match was required
I came across the same problem as you last year and gave up. I was describing the only workaround I could think of. It would be nice if clj-kondo didn't complain if you used a fully qualified var in this way. It should be able to infer that clojure.core.match is already loaded due to the transitive dependencies of the current namespace.
I appreciate the help Ambrose!
@borkdude what's your take on this scenario? could clj-kondo allow this because it can detect c.c.match is loaded via user-ns -> macro-ns?
;; macro namespace
(ns macro-ns
(:require [clojure.core.match :as m]))
(defmacro my-macro [& args] `(m/match ~@args))
;; macro usage namespace
(ns user-ns
(:require [macro-ns :refer [my-macro]]))
(macro-ns 1 2 3) ;<-- complains clojure.core.match is not required
;; macro hook namespace
(ns macro-hook
(:require [clojure.core.match :as m]))
(defmacro my-macro [& args] `(m/match ~@args))
Sorry, Iām down with a flu and will hopefully reply later
Get well soon!
The reason for the partial expansion is because I want clj-kondo to analyze the transformed code as match expressions
I think you need to expand the macro before giving it back to clj-kondo.