clj-kondo

https://github.com/clj-kondo/clj-kondo
kommen 2021-02-15T13:17:53.163Z

in our codebase we use a macro for setting up ns aliases without having to require the ns the alias resolves to (for the purpose of namespaced keywords, see https://ask.clojure.org/index.php/2817/lighter-weight-aliasing-for-keywords)

kommen 2021-02-15T13:19:53.164800Z

until now, we used clj-kondo’s :unresolved-namespace to not warn about usages of those aliases, which we mostly use for only a handful of namespaces. but I’m wondering if I can use the hooks to make it actually lint correctly

kommen 2021-02-15T13:23:13.167500Z

my best guess would be to use the hooks to transform our macro which sets up the alias to a

(require '[foo.bar :as bar])
node, as aliasing with require does work with kondo. would this be a viable approach?

borkdude 2021-02-15T13:40:27.167800Z

yes, that would be a good way

borkdude 2021-02-15T13:40:46.168200Z

since your company is sponsoring clj-kondo, would you like to have access to the private sponsor channel?

kommen 2021-02-15T13:41:19.168500Z

yes, please

kari 2021-02-15T15:09:50.170500Z

Trying to use clj-kondo (v2021.01.20) with IntelliJ Ultimate 2020.3.2 and Cursive 1.10.1-eap2-2020.3 with File Watchers as instructed here: https://github.com/clj-kondo/clj-kondo/blob/master/doc/editor-integration.md For some reason I can't see clj-kondo warnings in editor. Trying LSP next.

borkdude 2021-02-15T15:12:12.172Z

The clj-kondo LSP jar should work. I am not a Cursive user myself. What I wonder about is if the clojure-lsp plugin works for IntelliJ as well. That would be super awesome, since you get clj-kondo + many other things for free. @ericdallo?

kari 2021-02-15T15:31:39.173Z

Oh, god.

LanguageServer for definition
 rawCommand : java -jar /mnt/ssd2/local/bin/clj-kondo-2021.02.13-standalone.jar
not initialized after 15s
Check settings
Programming Clojure without clj-kondo is not worth living - I open my veins. πŸ™‚

kari 2021-02-15T15:35:05.173400Z

Ah, I just realized. It's not the lsp version.

kari 2021-02-15T15:35:31.173600Z

Stupid me. πŸ™‚

ericdallo 2021-02-15T15:43:58.173900Z

@borkdude it should work πŸ™‚ https://clojure-lsp.github.io/clojure-lsp/clients/#intellij-cursive

ericdallo 2021-02-15T15:44:20.174400Z

using that Intellij-lsp plugin: https://github.com/gtache/intellij-lsp

kommen 2021-02-15T16:02:21.175300Z

@borkdude any hint on how to best create a quoted node in a hook?

borkdude 2021-02-15T16:05:09.176400Z

@kommen yes, (api/list-node (list* (api/token-node 'quote) ...))) something like this

borkdude 2021-02-15T16:05:20.176700Z

so generate (quote foo) rather than 'foo

kari 2021-02-15T16:09:22.176800Z

LSP integration with IntelliJ / Cursive works nicely. I just first didn't realize that I get the warning tooltips only when I first click the yellow triangle in the upper right corner of the editor:

kommen 2021-02-15T18:47:16.177500Z

of course πŸ™ˆ

kommen 2021-02-15T18:47:21.177700Z

works like a charm, thank you!

πŸŽ‰ 1
borkdude 2021-02-15T18:48:26.178100Z

@kommen Related, there is also a linter to check alias consistency

kommen 2021-02-15T18:54:29.179700Z

yes, we’re using it, very useful. but I don’t see the connection on how this helps me here?

borkdude 2021-02-15T18:54:48.180100Z

it doesn't help, it's only related ;)

kommen 2021-02-15T18:55:00.180300Z

ok πŸ™‚

kommen 2021-02-15T18:56:33.181900Z

but the nice thing: with that hook for the macro now also lsp-find-references understands the aliases we’re setting up with it. this is so awesome

πŸŽ‰ 1
vemv 2021-02-15T19:48:06.183400Z

is there a kondo-based "find usages" thing? Maybe one that I can invoke from the repl? (clj-refactor offers this but it doesn't scale gracefully with project size)

borkdude 2021-02-15T19:48:42.183800Z

@vemv clojure-lsp uses clj-kondo to implement this

borkdude 2021-02-15T19:49:18.184400Z

other than that, you can also use the raw :analysis output (exactly the output that clojure-lsp uses)

vemv 2021-02-15T19:50:45.185600Z

guess I'll wait for https://github.com/clojure-lsp/clojure-lsp/issues/215 then :) and yes I suspected one can use :analysis - it's simply a matter of putting the time (which someone else might have invested already)

borkdude 2021-02-15T19:52:57.186400Z

There will be a talk about clojure-lsp Wednesday at the Dutch Clojure Meetup. 20:00 GMT+1

2
borkdude 2021-02-15T19:57:52.186700Z

online, in English ^

2
πŸ‡¬πŸ‡§ 2
borkdude 2021-02-15T20:08:53.187700Z

@vemv If I understand correctly, you want to leverage the logic from clojure-lsp from the REPL right? That may make sense, maybe clojure-lsp could publish part of their thing as a normal Clojure lib

πŸ‘ 1
borkdude 2021-02-15T20:09:01.187800Z

^ @ericdallo

ericdallo 2021-02-15T20:10:54.188800Z

Yes, I'm thinking on this and refactoring clojure-lsp code step by step to make this possible on the future πŸ˜„

2021-02-15T20:11:35.190Z

I'm also interested in this. Was actually browsing through clj-lsp's source to find some entry point πŸ˜…. (Stuck with raw analysis for now)

ericdallo 2021-02-15T20:11:45.190200Z

possible using a Stuart Sierra components arch

ericdallo 2021-02-15T20:13:03.190500Z

@jeroen.dejong I'm thinking about start exposing basic features first, like find-defintiion/references, but still need some hammock time

1
πŸ™‚ 1
borkdude 2021-02-15T20:13:11.190700Z

It might also be cool to do this from the cmd line, like:

clojure -X clojure-lsp/find-usages :var 'foo/bar'
or something.

✨ 3
ericdallo 2021-02-15T20:14:36.191500Z

Not sure yet how we would start, like classpath scan and etc

ericdallo 2021-02-15T20:14:50.191700Z

if they are cached like most of the time, this should be fast

borkdude 2021-02-15T20:14:57.191900Z

same as in the editor, if the scan is already there, skip it, else scan

ericdallo 2021-02-15T20:15:58.192100Z

Yeah, looks good

vemv 2021-02-15T20:32:45.192400Z

Good luck with the hammocking :) Looking forward to check out the end result

🀞 1
borkdude 2021-02-15T20:45:27.192700Z

I think a few of these functions could also live in clj-kondo proper, so you would do something like:

clojure -X clj-kondo.tools/find-var-usage :var 'foo/bar' :lint '...'  
but there you would need to pass clj-kondo the (class)paths of the sources to analyze.

πŸ‘ 1
borkdude 2021-02-15T21:04:30.193Z

@vemv Made a POC with commit 6451d5a22bd6bab3098f854d4c50dc704c709f9e

$ clojure -X clj-kondo.tools/find-references :var clojure.core/juxt :lint '["src"]'
{:references
 [{:fixed-arities #{1 3 2},
   :name-end-col 53,
   :name-end-row 301,
   :name-row 301,
   :name juxt,
   :filename "src/clj_kondo/impl/analyzer/namespace.clj",
   :from clj-kondo.impl.analyzer.namespace,
   :col 49,
   :name-col 49,
   :from-var analyze-require-clauses,
   :arity 2,
   :varargs-min-arity 3,
   :row 301,
   :to clojure.core}
  ...]}

❀️ 1
borkdude 2021-02-15T21:04:45.193200Z

(I'm pretty sure the API needs more hammock time)

1
ericdallo 2021-02-15T21:07:44.193400Z

Looks cool! I'll try to make something like that using the already existing queries on analysis

borkdude 2021-02-15T22:06:50.193900Z

I think I have a more flexible idea for the command line than building this inside clj-kondo, since everyone is going to want something slightly different anyway. Babashka script to the rescue! https://gist.github.com/borkdude/841d85d5ad04c517337166b3928697bd

1
πŸ†’ 1