Fork me on GitHub
#clj-kondo
<
2020-09-13
>
borkdude09:09:35

Does anyone using flycheck-clj-kondo want to take a look at this PR? https://github.com/borkdude/flycheck-clj-kondo/pull/10

sogaiu09:09:36

i don't use cider, but the actual code doesn't look like it is tied to cider. does that seem right?

borkdude09:09:08

that's right

sogaiu09:09:24

ok, i'll take a look then

sogaiu10:09:39

@borkdude ok, i've looked and tested a bit. i'd like to confirm that i understand the background of the situation. iiuc, in its current state, when one sends .cljc content to clj-kondo via stdin, using --lang clj or --lang cljs is likely to fail if there are any reader conditionals. does that sound right? so when using cider, there can be two repl connections, one to a clj repl and another to a cljs repl. i guess based on the current major-mode, which repl is used for evaluation is determined. so flycheck-clj-kondo also looks at the major mode to decide what value to use as the value for --lang. but this is a problem for .cljc content because if one is switched to either clojure-mode or clojurescript-mode, --lang will end up being passed clj or cljs, basically making it likely that clj-kondo cannot cope, getting something typically like this:

<stdin>:0:0: error: Can't parse <stdin>, Unparsable namespace form

sogaiu10:09:21

ok, so i think this pr tries to cope with this.

sogaiu10:09:54

it provides a buffer local variable that overrides things -- one can set it to "cljc".

borkdude10:09:07

That's right. I wondered about the use of eval, if this was legitimate there

sogaiu10:09:22

he he -- i am not so sure either.

sogaiu10:09:39

there is some other refactoring too which i wondered whether was necessary.

sogaiu10:09:03

@borkdude so i tried modifying the code a bit -- pulling the command construction back out into a let like before and not using eval. you might have guessed this, but that doesn't seem to work. may be it is because the value of flycheck-clj-kondo-lint-lang is then captured at macro compile time and consequently what one sets it to later is not reflected when constructing the command line to execute. does that sound plausible?

borkdude10:09:47

maybe the macros can all be turned into functions?

👍 3
sogaiu10:09:13

i can investigate that

sogaiu10:09:41

fwiw, it appears that using eval within the context of :command is a thing: https://github.com/flycheck/flycheck/issues/1515 this issue had to do with extending that to work for the first part of :command -- the one place it didn't (doesn't) work. which is not our case.

sogaiu11:09:17

@borkdude i'm not sure i quite follow about turning macros into functions. i did find that there is a function alternative (https://github.com/flycheck/flycheck/blob/master/flycheck.el#L5681) to the macro flycheck-define-checker, but i'm not sure how using that would help here. however, as far as constructing the command is concerned, there might be an alternative to using eval. i found a list here of the kinds of things one can use when constructing an arg for the command: https://github.com/flycheck/flycheck/blob/master/flycheck.el#L5899 (eval FORM) is one of the listed options, but there are also things like: https://github.com/flycheck/flycheck/blob/master/flycheck.el#L6002-L6004

borkdude11:09:01

ooh option-flag might be what we want here

sogaiu11:09:15

am looking for example usages

sogaiu11:09:05

will give it an attempt now

borkdude11:09:06

can we accomplish the desired behavior with that?

sogaiu11:09:51

@borkdude hmm, i think we want to fall back to lang if there is no value defined for flycheck-clj-kondo-lint-lang. i am not sure if option-flag will be enough.

borkdude11:09:52

option-flag takes not a default?

sogaiu11:09:39

it doesn't look like it to me. may be i misunderstood?

sogaiu11:09:11

fwiw, when searching for uses of option-flag i did find that it wasn't uncommon for flycheck things to be using eval.

borkdude11:09:40

ok, maybe it's alright then

sogaiu11:09:05

so we have done due diligence at least 🙂

borkdude11:09:11

yes, thanks for the review!

borkdude11:09:39

Maybe a bit bikesheddy, but maybe flycheck-clj-kondo-lang is a better name than flycheck-clj-kondo-lint-lang

sogaiu11:09:08

i did think the lint-lang version was a bit on the long side

sogaiu11:09:06

otoh this is emacs lisp 😛

borkdude11:09:30

I left a comment.

borkdude11:09:51

it's emacs lisp, but also kondo which emphasizes cleaning up things you don't need ;)

sogaiu11:09:09

ha ha ha -- good point