clj-kondo

imre 2025-02-23T16:24:24.667999Z

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?

imre 2025-02-28T17:55:07.030119Z

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

borkdude 2025-02-28T18:05:40.486589Z

awesome :)

imre 2025-02-28T18:24:11.209999Z

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

imre 2025-02-28T18:24:26.809219Z

anyway, it's late on a Friday evening so I'll deal with this another time

2025-02-28T18:44:38.264589Z

Looks like using metadata is an implementation detail. https://github.com/clj-kondo/clj-kondo/issues/2490#issuecomment-2671414913

borkdude 2025-02-28T18:45:16.069009Z

that's another way of using metadata though

imre 2025-02-24T09:08:03.093979Z

But I don't want to do that, because I want clj-kondo to analyze the call to core.match/match

imre 2025-02-24T09:10:17.859029Z

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

imre 2025-02-24T09:11:44.085979Z

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

imre 2025-02-24T15:12:57.129179Z

So what I need to do is turn mymacro into a match as if clojure.core.match was required

2025-02-24T18:32:17.301689Z

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.

imre 2025-02-24T18:41:29.016529Z

I appreciate the help Ambrose!

šŸ‘ 1
2025-02-24T18:44:45.501179Z

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

borkdude 2025-02-24T18:55:36.349929Z

Sorry, I’m down with a flu and will hopefully reply later

šŸ‘ 1
imre 2025-02-24T19:02:27.271739Z

Get well soon!

imre 2025-02-23T17:07:30.339919Z

The reason for the partial expansion is because I want clj-kondo to analyze the transformed code as match expressions

2025-02-23T18:34:31.391169Z

I think you need to expand the macro before giving it back to clj-kondo.