Is there a shell one-liner to make clj-kondo
return a non-zero exit code on errors only?
use case is using git rebase --interactive branch --exec "clj-kondo --lint ./src"
clj-kondo --lint - <<< '(inc)'; if [ $? -gt 2 ]; then exit 1; else exit 0; fi
hehe ok essentially what I was going to write in the script… fair enough 🙂
hmm ok small issue, running that actually terminates your shell… I guess that’s expected
clj-kondo --lint - <<< '(inc 0)'; bash -c "if [ $? -gt 2 ]; then exit 1; else exit 0; fi"
?
oh right, I guess this is better then:
clj-kondo --lint - <<< '(inc)'; if [ $? -gt 2 ]; then false; else true; fi
yeah that works better
thanks 🙇
hmm actually neither of those appear to halt the rebase exec
@rickmoynihan even shorter:
clj-kondo --lint - <<< '(inc)'; [[ $? -lt 2 ]]
again it doesn’t stop the exec
does ;
have the right behaviour?
sorry it should be:
$ clj-kondo --lint - <<< '(inc)'; [[ $? -le 2 ]]
<stdin>:1:1: error: clojure.core/inc is called with 0 args but expects 1
linting took 50ms, errors: 1, warnings: 0
this returns 1
on exit code 3
yeah was just looking at that
compare:
$ clj-kondo --lint - <<< '(inc)'; [[ $? -le 2 ]] && echo "we made it"
<stdin>:1:1: error: clojure.core/inc is called with 0 args but expects 1
linting took 43ms, errors: 1, warnings: 0
with:
$ clj-kondo --lint - <<< '(inc 2)'; [[ $? -le 2 ]] && echo "we made it"
linting took 12ms, errors: 0, warnings: 0
we made it
hmmm that still doesn’t seem to work 😕
it does work :)
not when I run like this though:
git rebase --interactive clj-kondo --exec "clj-kondo --lint ./src; [[ $? -le 2 ]]"
I’ve dropped a commit in the middle of a bunch that has a deliberate syntax error
and it doesn’t stop on it :thinking_face:
I don't know how bash and git rebase interact but at this point I give up and write babashka
😆
Perhaps an extra arg to clj-kondo to make all warnings return 0
would be a useful addition?
I think so yes
--allow-warnings
or something?
please come up with a couple more alternative names
--min-level warning
--min-level error
?
--non-zero-on-errors-only
(too long)
--ignore-warnings
would be misleading since clj-kondo still prints them
--fail-on warning
--fail-on error
--fail-on
seems better
putting it in a script works fine as you’d expect
nice
ok PR welcome
+ doc
Cool… I’ll maybe create an issue for it first
ok issue here: https://github.com/clj-kondo/clj-kondo/issues/1259
I'll ask @bozhidar how rubocop is calling this option
bozhidar We have something like this, let me look it up.
[4:15 PM] It's fail-level - <https://docs.rubocop.org/rubocop/usage/basic_usage.html#command-line-flags>
[4:16 PM] I think that's pretty common across linters.
https://github.com/clj-kondo/clj-kondo/pull/1261 Let me know if you want any changes
the issue may have been that $?
would interpolate inside double quotes... you'd want single quotes to delay that in this instance