Fork me on GitHub
Noah Bogart18:05:03

i've been writing a lot of hooks for my company's codebase and they've been great. i'm interested in writing something that checks multiple nodes at once. is that possible? are there any plans for such a thing?

👍 1

More details? I don't know what you mean with multiple nodes at once :)

Noah Bogart18:05:58

For example, I'd like to be able to write a hook that operates on a whole file, to allow for writing versions of :redefined-var.


ah multiple top level nodes...

👍 1
Noah Bogart18:05:52 gave me inspiration but there are multiple uses that come to mind


for warn on reflection I already have an issue: if you do Java interop and that form isn't there, then warn

👍 1
Noah Bogart19:05:41

i could write that in something other than clojure or just not using clj-kondo, lol, but it's so dang handy


for re-defined var, this is already a linter, what would you like to do differently there?


I see no reason why we couldn't have such a hook, but trying to get more compelling reasons for it

Noah Bogart19:05:25

At my job, we have separate namespaces for groups of routes using compojure.core/defroutes. We tend to keep those at the bottom of each of their files, but sometimes extra functions or comment blocks or other things can end up below. I'd like to enforce that each defroute expression is the final expression in a given namespace


another compelling thing could be to lint your own .edn files


so the hook could be named :analyze-file I guess?

👍 1

which is called at the beginning of any file


and the result can be transformed which will then be linted

Noah Bogart19:05:49

in addition to the one about requiring (set! *warn-on-reflection* true) below each ns form

Noah Bogart19:05:04

yeah, that's a good way to do it, actually


so there is one question that comes up with .cljc files. clj-kondo transforms such a file once for :clj and once for :cljs and then lints it


I suspect this hook wants to see the already transformed file... right?


else the user gets to deal with the difficulties of reader conditional processing

Noah Bogart19:05:04

that would probably be good. then users can write (defn my-file-hook [{:keys [lang]}] (when (= :clj lang) ...))


Can you write all of the above up in an issue?

Noah Bogart19:05:24

yes! i'll write it up for you

Noah Bogart19:05:18

thanks so much for being open to this idea! glad I could work through it with you


This touches on some a thing (linting .edn files) that was already in the queue for a while and I like this solution better since it's more flexible