Fork me on GitHub
#clj-kondo
<
2022-05-11
>
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
borkdude18:05:45

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.

borkdude18:05:39

ah multiple top level nodes...

👍 1
Noah Bogart18:05:52

https://clojurians.slack.com/archives/C053AK3F9/p1652285637355079 gave me inspiration but there are multiple uses that come to mind

borkdude19:05:38

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

borkdude19:05:12

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

borkdude19:05:30

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

borkdude19:05:11

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

borkdude19:05:21

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

👍 1
borkdude19:05:33

which is called at the beginning of any file

borkdude19:05:45

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

borkdude19:05:24

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

borkdude19:05:40

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

borkdude19:05:54

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

borkdude19:05:16

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

borkdude19:05:49

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