Fork me on GitHub
#clj-kondo
<
2024-01-05
>
Charles Comstock20:01:10

Is there a way to add verbose output showing every file that kondo is linting? I have a project with a somewhat odd directory structure below src and test and am not entirely convinced I'm linting every file from the --lint src test at the root. Any ideas on how to report everything kondo has checked?

borkdude20:01:36

Yes, with the --debug flag you will see every file linted

Charles Comstock20:01:43

Thank you, I did try that but that now seems to indicate it's not linting anything? I get a linting took message with 0 errors/warnings but no other output. Related, I wonder if that status message should also indicate the number of files processed? Anyway I will try and diagnose how to get it to process something

borkdude20:01:05

the EDN output might have the number of files:

clj-kondo --lint src test --config '{:output {:format :edn}}'

borkdude20:01:50

$ clj-kondo --lint src test --config '{:output {:format :edn}}' | jet -t ':summary :files'
74

Charles Comstock20:01:20

Thanks that is helpful. Oh... I'm getting different output if it's clj-kondo directly (which I think is stuck back at 2023.09.07 for me), vs the project level kondo install which is 2023.12.15. clj-kondo --lint src test correctly finds errors, but clj -Mclj-kondo --lint src test is not. My corresponding deps.edn alias is:

:clj-kondo
           {:extra-deps {clj-kondo/clj-kondo {:mvn/version "2023.12.15"}}
            :main-opts ["-m" "clj-kondo.main"]}
With the deps.edn kondo, if I specifically ask it to lint one file it will process it, but doesn't seem to be searching the directories correctly?

Charles Comstock20:01:25

Oh and this may be limited to the project I was having trouble with, which is quil, which has a mixture of src/{clj,cljs,cljc}/quil namespaces, as well as src/quil and test/quil. Did something change late this fall on how clj-kondo searches for files?

Charles Comstock20:01:29

$ clojure -M:clj-kondo --debug --lint src/cljs/quil/sketch.clj
[clj-kondo] Linting file: src/cljs/quil/sketch.clj
linting took 53ms, errors: 0, warnings: 0
$ clojure -M:clj-kondo --debug --lint src/cljs/
linting took 3ms, errors: 0, warnings: 0
$ clojure -M:clj-kondo --debug --lint src/cljs/quil/
linting took 3ms, errors: 0, warnings: 0
$ clojure -M:clj-kondo --debug --lint src/cljs/quil/*
[clj-kondo] Linting file: src/cljs/quil/sketch.clj
[clj-kondo] Linting file: src/cljs/quil/sketch.cljs
src/cljs/quil/sketch.cljs:4:14: warning: namespace goog.dom is required but never used
src/cljs/quil/sketch.cljs:6:14: warning: namespace goog.style is required but never used
src/cljs/quil/sketch.cljs:17:28: error: Unresolved symbol: rendering-modes
src/cljs/quil/sketch.cljs:17:44: error: keyword :java2d is called with 3 args but expects 1 or 2
src/cljs/quil/sketch.cljs:101:9: warning: unused binding features
linting took 136ms, errors: 2, warnings: 3
vs
$ clj-kondo --debug --lint src/cljs/quil/
[clj-kondo] Linting file: src/cljs/quil/sketch.cljs
[clj-kondo] Linting file: src/cljs/quil/helpers/tools.clj
[clj-kondo] Linting file: src/cljs/quil/sketch.clj
src/cljs/quil/sketch.cljs:4:14: warning: namespace goog.dom is required but never used
src/cljs/quil/sketch.cljs:6:14: warning: namespace goog.style is required but never used
src/cljs/quil/sketch.cljs:17:28: error: Unresolved symbol: rendering-modes
src/cljs/quil/sketch.cljs:17:44: error: keyword :java2d is called with 3 args but expects 1 or 2
src/cljs/quil/sketch.cljs:101:9: warning: unused binding features
linting took 30ms, errors: 2, warnings: 3

borkdude20:01:55

Its best to not use extra-deps but just deps with tools

borkdude20:01:22

Or replace-deps which the same as deps

borkdude20:01:56

Also you need to put a colon between -M:clj-kondo

borkdude20:01:59

There should not be any differences between the binary and JVM version

borkdude20:01:06

I can take a look tomorrow if you can put up a branch for me to clone and test

Charles Comstock20:01:03

Right but my clj-kondo install is 2023-09-07, vs the deps one is 2023.12.15. I tried swapping to extra-deps, replace-deps and just deps for the examples above and was still not finding any files. I'm not quite following -M:clj-kondo example, as I did include the colon. Give me a minute and I'll send you the branch to peruse at your leisure, thanks so much.

👍 1
Charles Comstock20:01:16

Yea I'm fixing the other locations it's missing a colon, but the examples above were using a colon and had same behavior. Will re-verify with everything updated though before sending you the branch.

Charles Comstock20:01:48

I don't have the --debug line in the script run on CI (and there are other errors that are unrelated), however if you checkout quil on that branch it should replicate the problem I was having with it skipping most of the files.

👍 1
Charles Comstock20:01:40

Thanks again. Separately, that colon/no-colon issue I keep getting confused about, I feel like sometimes it works anyway, but I'm not sure why when it fails. I'll have to bug the deps.edn folks about it at some point as it feels like a documentation issue but maybe I'm just missing something. Thanks for calling that out though.

borkdude20:01:09

it works but you're not supposed to omit it :)

borkdude20:01:56

one confusing recent addition to the deps CLI is that -Ttool and -T:tool mean two different things

borkdude20:01:08

anyway. I'll try your repo tomorrow

Charles Comstock20:01:31

Yea I had encountered it in -T so that makes sense, just wasn't sure why. Thanks again so much.

Charles Comstock21:01:15

One more datapoint. I checked out the branch on my laptop instead of my desktop to see if it was something on that machine somehow, and encountered the same behavior. Then I remembered I did have an alias for clj-kondo in my ~/.clojure/deps.edn and so I disabled that and still found the same behavior. However, as one last check, I tried my local copy of clj-kondo the binary which is v2023.10.20, and that has the same behavior as the deps.edn reference, ie it's not finding any files in src unless I specifically list them one by one.

borkdude21:01:25

I get the same results with both the newest clj-kondo binary and the JVM version - very weird

Charles Comstock21:01:11

So maybe something changed in how files are iterated over between 2023-09-07 and 2023.10.20?

borkdude21:01:53

I can debug this by checking out clj-kondo and use it as a local/root dependency (feel free to try if you are curious, will do myself tomorrow)

borkdude21:01:06

oh guess what, if I make a .clj-kondo directory it starts to work

borkdude21:01:10

so the bug may be around that

Charles Comstock21:01:46

oh interesting, well, that certainly at least gives a quick fix, and yep can confirm that works here too. Thanks for checking all this, I was having that sensation with software where you are uncertain how very many things work due to a bug that feels hyper-localized. That crazy feeling when software works almost how you expect, but has some little edge case that makes everything else feel like it might unravel. Anyway, very happy to hear that it's not a bug that only occurred on my machines, and happy to have a workaround, I suspect will need a .clj-kondo/config anyway.

Charles Comstock21:01:47

(also thank you very much both for your assistance today, and all your work on kondo and many other tools)

borkdude21:01:51

thank you! I'll file this as a bug and will fix it in the next release

lilactown20:01:13

if I have something that works just like reg-sub (registers a global keyword that can then be used with another function to look up the current value of that keyword) does clj-kondo have tools to build my own linter for it?

borkdude22:01:03

if you use :lint-as with the re-frame stuff, and it works the same syntactically, I think it should work. perhaps you can clarify your use case by giving some code

lilactown22:01:21

here's an example:

(defflag :foo "Enable feature 'foo'")

(feature-flag? :foo) ;; looks up if flag `:foo` is on and returns true/false

borkdude22:01:03

do you mean, you want to navigate from :foo in feature-flag? to the defflag? yes, this is possible, let me look it up

borkdude22:01:48

it's a bit cryptic but it's here:

:reg: can be added by :hooks using clj-kondo.hook-api/reg-keyword! to indicate a registered definition location for the keyword. It should be the fully qualified call that registered it.
https://github.com/clj-kondo/clj-kondo/blob/master/analysis/README.md also here:
reg-keyword!: indicates that a keyword's analysis should be marked as a definition. Expects the keyword node and either true or the fully-qualified function that registered it. This can be used to implement keyword navigation for clojure-lsp.
https://github.com/clj-kondo/clj-kondo/blob/master/doc/hooks.md if you write a hook which wraps the keyword in a reg-keyword! call (the exclamation mark is misleading, the return value should be used, then it should work with clojure-lsp

lilactown17:01:58

ah this is great. yeah I would love to get errors on usage of undefined keywords (feature-flag? with no corresponding defflag), and warnings on unused keywords (defflag with no corresponding feature-flag?)