Fork me on GitHub
#clj-kondo
<
2021-04-20
>
rickmoynihan12:04:01

Is there a shell one-liner to make clj-kondo return a non-zero exit code on errors only?

rickmoynihan12:04:41

use case is using git rebase --interactive branch --exec "clj-kondo --lint ./src"

borkdude12:04:49

clj-kondo --lint - <<< '(inc)'; if [ $? -gt 2 ]; then exit 1; else exit 0; fi

rickmoynihan12:04:58

hehe ok essentially what I was going to write in the script… fair enough 🙂

rickmoynihan12:04:20

hmm ok small issue, running that actually terminates your shell… I guess that’s expected

rickmoynihan12:04:02

clj-kondo --lint - <<< '(inc 0)'; bash -c "if [ $? -gt 2 ]; then exit 1; else exit 0; fi" ?

borkdude12:04:35

oh right, I guess this is better then:

clj-kondo --lint - <<< '(inc)'; if [ $? -gt 2 ]; then false; else true; fi

rickmoynihan12:04:29

yeah that works better

rickmoynihan12:04:18

hmm actually neither of those appear to halt the rebase exec

borkdude12:04:21

@rickmoynihan even shorter:

clj-kondo --lint - <<< '(inc)'; [[ $? -lt 2 ]]

rickmoynihan12:04:28

again it doesn’t stop the exec

rickmoynihan12:04:38

does ; have the right behaviour?

borkdude12:04:02

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

borkdude12:04:12

this returns 1 on exit code 3

rickmoynihan12:04:21

yeah was just looking at that

borkdude12:04:12

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

rickmoynihan12:04:13

hmmm that still doesn’t seem to work 😕

borkdude12:04:10

it does work :)

rickmoynihan12:04:35

not when I run like this though:

git rebase --interactive clj-kondo --exec "clj-kondo --lint ./src; [[ $? -le 2 ]]"

rwstauner14:04:47

the issue may have been that $? would interpolate inside double quotes... you'd want single quotes to delay that in this instance

👍 3
rickmoynihan12:04:28

I’ve dropped a commit in the middle of a bunch that has a deliberate syntax error

rickmoynihan12:04:35

and it doesn’t stop on it :thinking_face:

borkdude12:04:08

I don't know how bash and git rebase interact but at this point I give up and write babashka

rickmoynihan12:04:21

putting it in a script works fine as you’d expect

rickmoynihan12:04:26

Perhaps an extra arg to clj-kondo to make all warnings return 0 would be a useful addition?

borkdude12:04:35

I think so yes

rickmoynihan12:04:23

--allow-warnings or something?

borkdude12:04:12

please come up with a couple more alternative names

borkdude12:04:54

--min-level warning --min-level error ?

borkdude12:04:20

--non-zero-on-errors-only (too long)

borkdude12:04:58

--ignore-warnings would be misleading since clj-kondo still prints them

delaguardo12:04:39

--fail-on warning --fail-on error

rickmoynihan12:04:46

--fail-on seems better

borkdude12:04:54

ok PR welcome

rickmoynihan12:04:27

Cool… I’ll maybe create an issue for it first

borkdude13:04:45

I'll ask @bozhidar how rubocop is calling this option

borkdude14:04:06

bozhidar We have something like this, let me look it up.
[4:15 PM] It's fail-level - 
[4:16 PM] I think that's pretty common across linters.

👍 3