clj-kondo

https://github.com/clj-kondo/clj-kondo
borkdude 2021-01-22T17:20:57.022500Z

@didibus I just had another idea. Maybe clj-kondo can be equipped with a small nREPL client to double-check if some vars really don't exist, instead of a runtime plugin which you have to run yourself. Haha, wild idea.

2021-01-22T19:34:27.022800Z

Hum, could it be made into a middleware maybe?

2021-01-22T19:35:50.023Z

I have to say all the runtime things start to confuse me lol. Especially, I get confused how different it becomes then to what Cider does with nRepl already

borkdude 2021-01-22T19:36:06.023200Z

Yeah. Or maybe nREPL isn't such a good idea since it excludes other tooling like socket REPLs, so maybe it should be its own thing that clj-kondo can talk with. Just a one time data dump that you run every once in a while is easier

borkdude 2021-01-22T19:36:25.023400Z

And possibly this can work for CLJS as well

2021-01-22T19:54:49.023600Z

Hum. Well I was thinking. If say you had it as just a command: clj-kondo --runtime-analyze or something like that. Then I was wondering, could the editor, like in Anakondo, I could have an editor command that runs it on your project. And I could run it on your project the first time you open it up as well. Something like that. So maybe you don't need to "connect" to a REPL, maybe it could be something the editors integrate with.

2021-01-22T19:55:47.023800Z

In fact, could be an option to the analyzer, so it analyzes but also loads all ns, evals all top level forms, and returns the analysis from that, as well as populate the cache.

2021-01-22T19:56:39.024100Z

That way the analysis would also be able to list those vars that are created by the macros, and it could use it to auto-complete them and all.

borkdude 2021-01-22T19:56:50.024300Z

To load "all ns" you need to have a classpath. clj-kondo doesn't have a notion of classpath, it just takes what you feed it to --lint

borkdude 2021-01-22T19:57:22.024500Z

clj-kondo would have to invoke a JVM and/or the CLJS analyzer in the JVM

2021-01-22T19:57:35.024700Z

Ya, but the editor has a notion of classpath, so I could pass it to clj-kondo.

borkdude 2021-01-22T19:57:42.024900Z

That is right, you would get all the vars created by macros, that is the idea.

2021-01-22T19:58:32.025100Z

This might work better with the non native clj-kondo I guess. Would be easier as an alias, then it get the project classpath easilly.

borkdude 2021-01-22T19:58:45.025300Z

yeah, I think a JVM "co-pilot" program would make more sense than letting the clj-kondo binary do this

2021-01-22T19:58:49.025500Z

Ok, I see what you mean, ya it might be a seperate tool then I get it now.

borkdude 2021-01-22T20:00:12.025700Z

I think it should be a program similar to https://github.com/clj-kondo/inspector, or maybe it can all live inside that project

2021-01-22T20:01:24.026100Z

If I think of a nice workflow for it, like personally. I'd have it as part of my build. Like I have a step that compiles my code to see if there is any compile errors, then runs my tests, runs kibit, runs eastwood, runs clj-kondo. I can easily add that tool to this. The nice thing is, I naturally only run this when I know its going to compile, or when I'm about to commit or something like that.

borkdude 2021-01-22T20:02:50.026300Z

Yeah, and you can even commit the output of this to source control, like additional "config". https://github.com/clj-kondo/inspector/issues/5.

borkdude 2021-01-22T20:03:16.026700Z

I want it to be useful for editor integration myself, I'm using clj-kondo more during development than in CI

2021-01-22T20:03:30.026900Z

Ya, its the ergonomics I'm trying to imagine. If its too REPLy, well, I mean, people already used to Repls and Cider will have no issue. But the aspect of clj-kondo of like: it just works even if I'm a beginner, would be a bit lost to this.

borkdude 2021-01-22T20:04:14.027200Z

yeah, that's why I was thinking, if clj-kondo could peek into a running REPL, this would not require you to run this tool

borkdude 2021-01-22T20:04:32.027400Z

and I could easily bake in some thin nREPL ops into kondo

2021-01-22T20:05:37.027700Z

I'm just wondering, in the REPL, how would you distinguish between a var that ther user defined in the REPL only, and is actually missing from the source code (even in the sense that the code to def it isn't there).

borkdude 2021-01-22T20:05:58.027900Z

I would use the runtime output only as a second opinion to prevent false positives

borkdude 2021-01-22T20:06:38.028100Z

e.g. (defvars x y z). x is unresolved, check runtime output, ooh, it's there, ok, ignore.

2021-01-22T20:07:15.028300Z

I guess its because I'm coming from the perspective of tools.namespace refresh. People will often like eval a defn and later delete it. So now if you peek in the REPL, you will see that it is there, but that's the bug they want to be warned against.

borkdude 2021-01-22T20:07:58.028500Z

yeah, that's true, this is also where clj-kondo shines right now: it will tell you the var doesn't exist anymore .. hmm

2021-01-22T20:08:27.028700Z

Its like a battle between false positive and false negative 😛

borkdude 2021-01-22T20:08:40.028900Z

yeppp

borkdude 2021-01-22T20:09:16.029100Z

I'm almost convinced now by your argument that this isn't going to result in an improvement ;)

😁 1
2021-01-22T20:09:39.029300Z

Personally, for this use case, I'd lean on false positive. Cause I would see, oh it says that var is missing? Oh but this is a special var being deffed by hugsql, ok let me just add it to the clj-kondo exclusion.

borkdude 2021-01-22T20:09:57.029500Z

yeah

borkdude 2021-01-22T20:10:14.029800Z

the new unresolved var linter saved my ass a couple of times already today

borkdude 2021-01-22T20:10:29.030Z

thanks for leading me through the issue by testing, it really helps to get feedback and not get stranded

2021-01-22T20:10:43.030200Z

I did the easy part 😛

2021-01-22T20:10:50.030400Z

Thank you for the hard work

borkdude 2021-01-22T20:12:09.030600Z

no problem. this issue was at the top of the list for a while... I noticed I accidentally made the level :warning by default

borkdude 2021-01-22T20:12:21.030800Z

instead of :error, but maybe that's a good choice for the initial release

2021-01-22T20:12:27.031Z

I honestly feel clj-kondo is the game changer Clojure was missing. Like because we can interop with Java, almost all other Clojure libs are redundant, even if I like a good Clojure lib over Java interop, I can easily make without. But, the IntelliJ like instant fedback of squiggly lines like hey this isn't how the syntax works, or like dummy you have a typo, this is what I was missing most from Java and C# 😛

2021-01-22T20:13:27.031200Z

I don't think its possible to try clj-kondo, and then decide to go back to not using it haha

2021-01-22T20:13:37.031400Z

So thank you for making it!

borkdude 2021-01-22T20:14:12.031600Z

Yeah, the initial inspiration was joker: it showed the potential

borkdude 2021-01-22T20:14:41.031800Z

And then GraalVM native-image came along, rewrite-clj luckily worked the first time, and boom, the right combination

💯 1
2021-01-22T20:14:48.032Z

Its also neat how indirectly, you're leading the way for native compilation of Clojure as well

2021-01-22T20:19:01.032300Z

I also love sci and babashka haha 😂

2021-01-22T20:19:26.032500Z

Just showing my gratitude here. Alright, got to go. Ttyl

borkdude 2021-01-22T20:19:48.032700Z

Thanks a lot, cya!