clj-kondo

2025-06-17T16:10:26.973469Z

i searched for taoensso/carmine and saw that due to no exported clj-kondo config, better to just exclude unresolved-var . but given that there's a https://github.com/taoensso/carmine/blob/97cefd0aaf7f4bae56257634ea5423801a7a1ca6/resources/carmine-commands.edn file that shows everything it autogenerates, i could conceivably just parse and build those for clj-kondo. is it possible to "intern" vars into clj-kondo's understanding of a given namespace, which would then be used in analysis?

✅ 1
borkdude 2025-06-17T16:13:15.885829Z

I guess you could generate a hook from that EDN file that does what the macro does to define some vars

borkdude 2025-06-17T16:13:32.620819Z

even if it would just do a bunch of declares

2025-06-17T16:27:01.608769Z

huh, interseting idea

2025-06-17T17:31:56.445189Z

any ideas how i'd write that? i'm trying to use :macroexpand but struggling

borkdude 2025-06-17T17:56:02.669929Z

what have you tried so far? I'm suggesting to actually generate the macroexpand hook file using some script outside of kondo which can read the .edn file and spits out the hook file which clj-kondo can then use

2025-06-17T17:56:30.720359Z

oh i see, i was trying to generate it from within the hooks file

2025-06-17T17:57:30.078379Z

so build a file that has a bunch of (defn foo [{:keys [node]}] ...) lines, and then have a config file that says {:hooks {:analyze-call {carmine/foo hooks.carmine/foo ...}}}?

borkdude 2025-06-17T17:58:01.147139Z

yes

2025-06-17T17:58:15.213319Z

cool, thanks for the idea, i went about it totally wrong lol

borkdude 2025-06-17T17:58:21.160119Z

it could also be a :macroexpand-hook

borkdude 2025-06-17T17:58:34.312549Z

doesn't matter, as long as you generate a bunch of declare ...

borkdude 2025-06-17T17:58:46.228779Z

assuming that carmine uses some kind of macro to define those

2025-06-17T18:01:28.662579Z

yes, it does

2025-06-17T19:47:07.218499Z

hmm i can't seem to make this work

2025-06-17T19:48:51.859979Z

i have a hook file in .clj-kondo/hooks/taoensso/carmine/commands.clj:

(ns hooks.taoensso.carmine.commands
  (:require
   [clj-kondo.hooks-api :as api]))

(def commands '("foo" ...))

(defn make-declare [token]
  (api/list-node [(api/token-node 'declare) (api/token-node token)]))

(defn defcommands
  [{:keys [_node]}]
  (prn _node)
  (let [declares (mapv make-declare commands)
        new-node (api/list-node
                  (list*
                   (api/token-node 'do)
                   declares))]
    {:node new-node}))
and then in config.edn, i have
{:hooks {:analyze-call {taoensso.carmine.commands/defcommands hooks.taoensso.carmine.commands/defcommands}}}
and then i run
$ clj-kondo --lint src/[REDACTED]/queue.clj --debug
[clj-kondo] Auto-loading config path: imports/rewrite-clj/rewrite-clj
[clj-kondo] Auto-loading config path: imports/taoensso/encore
[clj-kondo] Auto-loading config path: imports/nubank/matcher-combinators
[clj-kondo] Auto-loading config path: imports/babashka/sci
[clj-kondo] Auto-loading config path: imports/babashka/fs
[clj-kondo] Linting file: src/[REDACTED]/queue.clj
linting took 32ms, errors: 0, warnings: 0

2025-06-17T19:51:59.333969Z

hmm jk, it is working? nothing is printed, but the calls aren't flagged as wrong

borkdude 2025-06-17T19:52:09.106259Z

You should lint carmines source to activate the hook?

2025-06-17T19:52:18.275749Z

ah okay

2025-06-17T19:55:09.334809Z

i still don't get why it doesn't print, but it does seem to work now. thanks for the help

2025-06-17T20:01:49.815289Z

oh, it prints when i lint the dependencies, not when i lint my own code. that makes sense