clj-kondo

https://github.com/clj-kondo/clj-kondo
Jim Newton 2020-10-30T10:26:54.240700Z

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?

borkdude 2020-10-30T10:27:36.241300Z

@jimka.issy There are several options for this: https://github.com/borkdude/clj-kondo/blob/master/doc/config.md#unrecognized-macros

Jim Newton 2020-10-30T10:31:03.242200Z

hmmm. are those workarounds really satisfying to kondo users?

Jim Newton 2020-10-30T10:31:41.242700Z

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

Jim Newton 2020-10-30T10:31:57.243400Z

and even report that macroexpand fails.

borkdude 2020-10-30T10:32:48.244400Z

@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

borkdude 2020-10-30T10:33:44.245500Z

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 Newton 2020-10-30T10:33:54.245800Z

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.

borkdude 2020-10-30T10:35:01.247Z

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 Newton 2020-10-30T10:36:02.247700Z

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

borkdude 2020-10-30T10:36:29.248300Z

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

Jim Newton 2020-10-30T10:37:00.249Z

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

borkdude 2020-10-30T10:37:07.249300Z

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

borkdude 2020-10-30T10:37:53.249900Z

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

Jim Newton 2020-10-30T10:37:57.250100Z

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

borkdude 2020-10-30T10:38:34.250800Z

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

Jim Newton 2020-10-30T10:38:50.251Z

i see.

borkdude 2020-10-30T10:39:23.252200Z

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 Newton 2020-10-30T10:39:25.252300Z

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

borkdude 2020-10-30T10:39:53.252800Z

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

borkdude 2020-10-30T10:40:19.253600Z

Here is a repo with hooks for some libraries: https://github.com/clj-kondo/config

Jim Newton 2020-10-30T10:40:28.253900Z

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

borkdude 2020-10-30T10:41:34.254600Z

Ever heard of the first rule of macro club? :) https://stuartsierra.com/download/2010-10-23-clojure-conj-macro-club.pdf

borkdude 2020-10-30T10:42:37.255200Z

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 Newton 2020-10-30T10:50:48.255700Z

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

Jim Newton 2020-10-30T10:51:04.256200Z

I very often use the Common Lisp definition order.

borkdude 2020-10-30T10:54:28.257600Z

@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 Newton 2020-10-30T10:59:10.258300Z

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

borkdude 2020-10-30T11:00:15.258600Z

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

Jim Newton 2020-10-30T11:01:14.259600Z

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?

borkdude 2020-10-30T11:02:18.260500Z

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

Jim Newton 2020-10-30T11:03:30.261200Z

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

borkdude 2020-10-30T11:04:22.262200Z

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 Newton 2020-10-30T11:04:33.262500Z

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

borkdude 2020-10-30T11:04:51.262900Z

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

borkdude 2020-10-30T11:06:46.263200Z

maybe the README should mention that

Jim Newton 2020-10-30T11:11:41.263800Z

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.

borkdude 2020-10-30T11:13:39.264100Z

Github issue would be good

Jim Newton 2020-10-30T11:16:48.264500Z

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

borkdude 2020-10-30T11:17:38.264800Z

yeah

Jim Newton 2020-10-30T11:28:59.265400Z

OK, I filed a issue #1054 https://github.com/borkdude/clj-kondo/issues/1054 Thanks for the offer to take a look.

borkdude 2020-10-30T11:37:12.267Z

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.

borkdude 2020-10-30T11:38:00.267500Z

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

borkdude 2020-10-30T22:58:54.268600Z

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.