clj-kondo 2025-12-15

I want to load a Clojure source file and extract all forms that satisfy some requirements. Let's say I wanted to find all the hiccup vectors that starts with :h1, e.g. [:h1 "Hello"] and [:h1 (:title blog-post)]. I've accomplished this now with some hackery including slurp read-string and tree-seq, but I did have to manually expand namespace aliases etc, it doesn't work with reader conditionals etc etc. Does kondo have some functionality I can lean on to do this? Or should I be looking at edamame?

Here's the current open Hiccup issue: https://github.com/clj-kondo/clj-kondo/issues/2660 Michiel's https://github.com/clj-kondo/clj-kondo/tree/hiccup does something similar to what you're asking for!

I'm not specifically asking about hiccup, my question is more general about how can I find forms that satisfy some requirements? But I'll have a look at the branch

the clj-kondo branch is about verifying hiccup, not about finding hiccup forms as a general tool. for finding forms, you could use edamame. it has this option for automatically reading stuff based on the ns form too: https://github.com/borkdude/edamame?tab=readme-ov-file#auto-resolve-ns

👍 1

Ah, lovely

for reader conditionals, you can add :read-cond :allow + :features (constantly true) to pick the first reader conditional. or you can use :read-cond my-function to manually process reader conditional lists.

The reason I started with kondo was the analyzer. It felt like the analyzer would need to do the things I wanted to do to come up with its answer

1

Awesome, thanks 👍

https://github.com/borkdude/grasp is also a little tool to detect forms based on a pattern specified via clojure.spec but it's basically tree-seq + some more logic that you could easily build yourself too with edamame

edamame automatically attaches metadata to vectors so you have the location (probably you need this for your purposes...?)

Yeah, that'll be useful 🙂

👍 1

you can control this with :location seq? if you want the default clojure behavior

👍 1

This is perfect, does exactly what I needed 🙌

https://github.com/clj-commons/rewrite-clj is another tool worth knowing about in this area, imo ... We have done lots of fun 'code is data' things with it.

👍 1
➕ 1