Fork me on GitHub
#clj-kondo
<
2021-02-15
>
kommen13:02:53

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)

kommen13:02:53

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

kommen13:02:13

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?

borkdude13:02:27

yes, that would be a good way

borkdude13:02:46

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

kommen13:02:19

yes, please

kari15:02:50

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.

borkdude15:02:12

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?

kari15:02:39

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. ๐Ÿ™‚

kari15:02:05

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

kari16:02:22

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:

kari15:02:31

Stupid me. ๐Ÿ™‚

kommen16:02:21

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

borkdude16:02:09

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

borkdude16:02:20

so generate (quote foo) rather than 'foo

kommen18:02:16

of course ๐Ÿ™ˆ

kommen18:02:21

works like a charm, thank you!

๐ŸŽ‰ 3
borkdude18:02:26

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

kommen18:02:29

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

borkdude18:02:48

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

kommen18:02:00

ok ๐Ÿ™‚

kommen18:02:33

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

๐ŸŽ‰ 3
vemv19:02:06

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)

borkdude19:02:42

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

borkdude19:02:18

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

vemv19:02:45

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)

borkdude19:02:57

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

6
borkdude19:02:52

online, in English ^

๐Ÿ‡ฌ๐Ÿ‡ง 6
clojure-lsp 6
borkdude20:02:53

@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

๐Ÿ‘ 3
ericdallo20:02:54

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

thumbnail20:02:35

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)

ericdallo20:02:45

possible using a Stuart Sierra components arch

ericdallo20:02:03

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

๐Ÿ™‚ 3
hammock 3
borkdude20:02:11

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

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

โœจ 9
ericdallo20:02:36

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

ericdallo20:02:50

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

borkdude20:02:57

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

ericdallo20:02:58

Yeah, looks good

vemv20:02:45

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

๐Ÿคž 3
borkdude20:02:27

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.

๐Ÿ‘ 3
borkdude21:02:30

@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}
  ...]}

โค๏ธ 3
borkdude21:02:45

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

hammock 3
ericdallo21:02:44

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

borkdude22:02:50

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

๐Ÿ†’ 3
babashka 3