clj-kondo

2024-11-21T14:03:05.669049Z

Today I had a major slamming-head-into-desk moment, after having wondered for a while why the code wasn't quite as clever as I thought it should be. 😅 Maybe it would be interesting for clj-kondo to help me avoid being this stupid in the future? 🙈

(or option1 option1)
In case it is not clear, this was supposed to be
(or option1 option2)
🙈

😅 6
borkdude 2024-11-21T16:31:21.228329Z

:redundant-argument could be a linter. applicable to or and merge possibly more? but not sure how common this is...

MJ 2024-11-21T19:56:35.253229Z

you'd also have to account for side-effecting functions, like (or (.next iter) (.next iter)) . Or just only apply the warning for simple var args, but then that limits its usefulness even further

borkdude 2024-11-21T19:57:33.149719Z

I was thinking just symbols, but yeah that doesn't seem very useful

2024-11-21T16:22:37.769899Z

how do i make clj-kondo only lint a given language in cljc files?

borkdude 2024-11-21T16:25:44.434419Z

{:cljc [:clj]}

2024-11-21T16:25:54.256129Z

thank you

borkdude 2024-11-21T16:26:41.164449Z

no sorry: {:cljc {:features [:clj]}}

2024-11-21T16:29:33.081749Z

That's not listed anywhere in doc/config.md. Would you accept a PR to document it?

borkdude 2024-11-21T16:30:16.627329Z

yes

grahamcarlyle 2024-11-21T16:38:20.086329Z

Is there a way to have any :info level warning fail kondo? i believe i can change a linter's level on a case by case basis, but i was wondering if i could default fail on an info level warn?

Ed 2024-11-22T11:04:42.485429Z

You could always parse the output of clj-kondo to detect the info level and return a different status code?

% clj-kondo --lint common/test/scratch/common_test.cljc | tee - >&2 | if grep -E '^[^ ]*: (error|warning|info):' >/dev/null; then echo error ; exit  1 ; else echo success ; exit 0 ; fi
common/test/scratch/common_test.cljc:2:98: warning: #'clojure.test/are is referred but never used
common/test/scratch/common_test.cljc:2:98: warning: #'cljs.test/are is referred but never used
linting took 15ms, errors: 0, warnings: 2
error
if you ran it something like that then you'd get a different exit code for info messages. Not sure if that's any better than the solution you already have, but it might need less upkeep?

👍 1
1
borkdude 2024-11-21T16:42:15.702959Z

no, by definition info is a non-failure

grahamcarlyle 2024-11-21T16:47:27.527419Z

ah, is there a way to raise all info linters to warning without explicitly naming them?

grahamcarlyle 2024-11-21T16:50:07.816729Z

i was trying to get to a point where I have to action all linters that have output in our CI system and by default I want to deal with linters that default to info level

borkdude 2024-11-21T16:50:59.904889Z

nope, not possible, be explicit

grahamcarlyle 2024-11-21T16:58:02.056239Z

thats a shame as i think that means i have to either keep eye-balling the output of kondo for info that i would like to fail on, or stop reporting on info and so lose awareness of new info level linters

borkdude 2024-11-21T17:00:58.638959Z

we could perhaps support --fail-level info but it sounds wrong to me ;)

grahamcarlyle 2024-11-21T17:01:46.698959Z

yeah conceptually i think i want to raise those info level linters to warning, and only explicitly downgrade them to info when i think they aren't important

borkdude 2024-11-21T17:01:57.357049Z

exactly

grahamcarlyle 2024-11-21T17:03:15.670809Z

i think my best way forward is to raise to warning the existing info level linters and just keep an eye out for new info ones to either raise or ignore

borkdude 2024-11-21T17:04:08.385149Z

you can get all linters from here: https://github.com/clj-kondo/clj-kondo/blob/071e557f9dce447953db7ff96929b92d283c4462/src/clj_kondo/impl/config.clj#L21 it's officially an implementation detail but perhaps I could expose an officially supported linter map so you could programmatically do this or so

Kirill Chernyshov 2024-11-21T17:09:35.759969Z

but there are --fail-lever and --report-level already. --fail-level info will force kondo to exit with a non-zero exit code.

borkdude 2024-11-21T17:11:01.533099Z

--report-level doesn't affect the exit code AFAIK. --fail-level only supports warning and error, it's documented

Kirill Chernyshov 2024-11-21T17:12:22.118229Z

nevermind, info is not supported by fail-level

grahamcarlyle 2024-11-21T17:13:54.883339Z

i think having programmatic access to the linter map would be good as that would allow me to have a CI job that would fail if an info level linter came into existence that i wasn't either raising or ignoring

grahamcarlyle 2024-11-21T17:14:59.875299Z

i guess i can just do that now with the "unofficial" default-config you pointed out

borkdude 2024-11-21T17:15:07.015879Z

sure