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?
@jimka.issy There are several options for this: https://github.com/borkdude/clj-kondo/blob/master/doc/config.md#unrecognized-macros
hmmm. are those workarounds really satisfying to kondo users?
I use lots of macros in my code, it would be great if kondo would check the expanded code.
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.
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.
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)
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
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
i see.
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
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: https://github.com/clj-kondo/config
not your fault of course, but it is unfortunate that such a powerful feature of the language is discouraged.
Ever heard of the first rule of macro club? :) https://stuartsierra.com/download/2010-10-23-clojure-conj-macro-club.pdf
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
kondo does find lots of problems with my code. notably misplaced docstrings.
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.
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.
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: https://github.com/borkdude/clj-kondo/#project-setup
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.
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
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
By "Which platform are you using?" You mean Mac/Linux/windows?
yeah
OK, I filed a issue #1054 https://github.com/borkdude/clj-kondo/issues/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: https://github.com/borkdude/grasp I just added an example of how to find all occurrences of keywords in e.g. a re-frame app: https://github.com/borkdude/grasp#finding-keywords Discuss in #grasp for more.