clj-kondo

https://github.com/clj-kondo/clj-kondo
2021-04-20T12:12:01.277700Z

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

2021-04-20T12:12:41.278400Z

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

borkdude 2021-04-20T12:12:49.278700Z

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

2021-04-20T12:13:58.279400Z

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

2021-04-20T12:17:20.280500Z

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

2021-04-20T12:18:02.280800Z

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

borkdude 2021-04-20T12:18:35.281100Z

oh right, I guess this is better then:

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

borkdude 2021-04-20T12:19:16.281300Z

^ @rickmoynihan

2021-04-20T12:19:29.281500Z

yeah that works better

2021-04-20T12:19:34.281700Z

thanks 🙇

2021-04-20T12:23:18.282400Z

hmm actually neither of those appear to halt the rebase exec

borkdude 2021-04-20T12:24:21.282700Z

@rickmoynihan even shorter:

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

2021-04-20T12:25:28.283Z

again it doesn’t stop the exec

2021-04-20T12:25:38.283300Z

does ; have the right behaviour?

borkdude 2021-04-20T12:30:02.284100Z

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

borkdude 2021-04-20T12:30:12.284400Z

this returns 1 on exit code 3

2021-04-20T12:30:21.284700Z

yeah was just looking at that

borkdude 2021-04-20T12:31:12.285300Z

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

2021-04-20T12:31:13.285500Z

hmmm that still doesn’t seem to work 😕

borkdude 2021-04-20T12:32:10.285800Z

it does work :)

2021-04-20T12:32:35.286200Z

not when I run like this though:

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

2021-04-20T12:33:28.286900Z

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

2021-04-20T12:33:35.287200Z

and it doesn’t stop on it :thinking_face:

borkdude 2021-04-20T12:34:08.287900Z

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

2021-04-20T12:34:19.288100Z

😆

2021-04-20T12:35:26.289Z

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

borkdude 2021-04-20T12:35:35.289200Z

I think so yes

2021-04-20T12:36:23.289700Z

--allow-warnings or something?

borkdude 2021-04-20T12:37:12.290100Z

please come up with a couple more alternative names

borkdude 2021-04-20T12:37:54.290800Z

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

borkdude 2021-04-20T12:38:20.291300Z

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

borkdude 2021-04-20T12:38:58.291700Z

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

2021-04-20T12:39:39.292500Z

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

2021-04-20T12:40:46.292900Z

--fail-on seems better

2021-04-20T12:43:21.293Z

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

borkdude 2021-04-20T12:45:48.293300Z

nice

borkdude 2021-04-20T12:45:54.293500Z

ok PR welcome

borkdude 2021-04-20T12:46:07.293700Z

+ doc

2021-04-20T12:46:27.294100Z

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

2021-04-20T12:57:16.294300Z

ok issue here: https://github.com/clj-kondo/clj-kondo/issues/1259

borkdude 2021-04-20T13:01:45.294900Z

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

borkdude 2021-04-20T14:19:06.295100Z

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.

👍 1
2021-04-21T22:50:08.296300Z

https://github.com/clj-kondo/clj-kondo/pull/1261 Let me know if you want any changes

rwstauner 2021-04-20T14:55:47.295200Z

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

👍 1