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)
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
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?yes, that would be a good way
since your company is sponsoring clj-kondo, would you like to have access to the private sponsor channel?
yes, please
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.
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?
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. πAh, I just realized. It's not the lsp version.
Stupid me. π
@borkdude it should work π https://clojure-lsp.github.io/clojure-lsp/clients/#intellij-cursive
using that Intellij-lsp
plugin: https://github.com/gtache/intellij-lsp
@borkdude any hint on how to best create a quoted node in a hook?
@kommen yes, (api/list-node (list* (api/token-node 'quote) ...)))
something like this
so generate (quote foo)
rather than 'foo
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:
of course π
works like a charm, thank you!
@kommen Related, there is also a linter to check alias consistency
yes, weβre using it, very useful. but I donβt see the connection on how this helps me here?
it doesn't help, it's only related ;)
ok π
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
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)
@vemv clojure-lsp uses clj-kondo to implement this
other than that, you can also use the raw :analysis output (exactly the output that clojure-lsp uses)
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)
There will be a talk about clojure-lsp Wednesday at the Dutch Clojure Meetup. 20:00 GMT+1
online, in English ^
@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
Yes, I'm thinking on this and refactoring clojure-lsp code step by step to make this possible on the future π
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)
possible using a Stuart Sierra components arch
@jeroen.dejong I'm thinking about start exposing basic features first, like find-defintiion/references, but still need some hammock time
It might also be cool to do this from the cmd line, like:
clojure -X clojure-lsp/find-usages :var 'foo/bar'
or something.Not sure yet how we would start, like classpath scan and etc
if they are cached like most of the time, this should be fast
same as in the editor, if the scan is already there, skip it, else scan
Yeah, looks good
Good luck with the hammocking :) Looking forward to check out the end result
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.@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}
...]}
(I'm pretty sure the API needs more hammock time)
Looks cool! I'll try to make something like that using the already existing queries on analysis
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