Fork me on GitHub
Jim Newton10:10:54

Hi everyone, just started using kondo. question. what should I do to make it not complain about my macros? Or better, to make it check macros correctly?

Jim Newton10:10:03

hmmm. are those workarounds really satisfying to kondo users?

Jim Newton10:10:41

I use lots of macros in my code, it would be great if kondo would check the expanded code.

Jim Newton10:10:57

and even report that macroexpand fails.


@jimka.issy This is a general problem in Clojure and static analysis tooling. The trade off is either execute macros at the penalty of performance and launching missiles or mechanisms like this to assist static analysis which make it feasible for near realtime feedback


The closest thing for making clj-kondo aware of your custom macros and getting good custom checks is writing hooks for it. The other options are linting as existing macros or suppressing warnings.

Jim Newton10:10:54

yes, that is a real trade off. I realize that some macros (even some of my own) are really cpu intensive. But I'd love the option, as most macros are NOT cpu intensive, but simple code transformations.


When writing the hooks API I have considered that. But it isn't possible since keywords, numbers, strings etc, do not carry metadata, so you will lose location information. It's not likely that clj-kondo will support executing user macros as is anytime soon.

Jim Newton10:10:02

is clj-kondo executing in a different process? or is it executing in the same nrepl process as emacs/cider is using?


Clj-kondo is its own environment, not attached to the JVM at all (if you're running the binary)

Jim Newton10:10:00

it's not using the JVM? that sounds like a huge amount of work.


You can lint arbitrary .clj and .cljs files on a system without any other Clojure tools on it


@jimka.issy If you like to use a JVM-attached linter that will expand your macros take a look at eastwood

Jim Newton10:10:57

do my comments echo every first-time user's comments? sorry if they do.


It's a common question, but in most projects I've worked on, the macro config only contains a hand full of things


In Clojure writing lots of macros isn't really encouraged anyway. Clj-kondo supports most well known macros, at least from Clojure itself and several popular libraries

Jim Newton10:10:25

It seems I looked at eastwood sometime ago and abandoned it. Perhaps because it easily gets confused with namespaces.


And hooks offer enough flexibility to support the wildest custom macros now


Here is a repo with hooks for some libraries:

Jim Newton10:10:28

not your fault of course, but it is unfortunate that such a powerful feature of the language is discouraged.


I mean, I do use them, and it's annoying that clj-kondo doesn't recognize the syntax out of the box, but it's not something I can easily fix while also keeping clj-kondo fast and accurate

Jim Newton10:10:48

kondo does find lots of problems with my code. notably misplaced docstrings.

Jim Newton10:10:04

I very often use the Common Lisp definition order.


@jimka.issy The initial inspiration for clj-kondo was joker: it's a linter that I could easily hook up with emacs and it worked without a running REPL. I extended the way it works with more features and this became clj-kondo. You can watch the talk in the README (ca. 20 minutes long) if you want to know more about how clj-kondo works and the trade-offs it makes.

Jim Newton10:10:10

how does condo figure out whether a symbol is resolvable. It seems to get this wrong in lots of cases for me.


It depends. If you have a concrete example, I can tell you why.

Jim Newton11:10:14

I suspect it is related to (in-ns ...) does clj-kondo know that top-level regions between two calls to (in-ns ...) should be interpreted in the name space specified?


It knows. But if clj-kondo hasn't linted the other ns yet, it might not know which symbols are in it. To make clj-kondo aware of this, you should do this:

Jim Newton11:10:30

yes I did that before I started. do I need to redo it from time to time?


in that case, it might be a bug. Not sure. If you can make a repro as in: I've linted this file and I'm using in-ns of the ns of that file in this other file, but it doesn't work, I will take a look.

Jim Newton11:10:33

BTW when I parallel lint, it printed out volumes of diagnostics from libraries I'm referencing


yeah, you can ignore that with > /dev/null if you want


maybe the README should mention that

Jim Newton11:10:41

I'm happy to send you the issue by email, or chat, or and also happy to file it in the issue tracker on github as you prefer.


Github issue would be good

Jim Newton11:10:48

By "Which platform are you using?" You mean Mac/Linux/windows?

Jim Newton11:10:59

OK, I filed a issue #1054 Thanks for the offer to take a look.


Thanks. I hope to take a look soon. I think the in-ns logic might not remember the requires from the original ns well enough, something along those lines.


meanwhile, as a workaround you can use namespace local config to suppress those symbols


Users of clj-kondo may also like: I just added an example of how to find all occurrences of keywords in e.g. a re-frame app: Discuss in #grasp for more.