Fork me on GitHub
#clj-kondo
<
2019-11-28
>
ericdallo13:11:32

Thank you for this very useful feature. I tested on my Debian 10 linux using the binary above and it seems to work nice

borkdude12:11:24

The name of the linter and the message are subject to change, feel free to post suggestions at https://github.com/borkdude/clj-kondo/issues/339

stathissideris13:11:43

hello, is there a way to exclude certain namespaces (with a regex) from being checked for :unresolved-symbol?

borkdude13:11:38

https://github.com/borkdude/clj-kondo/blob/master/doc/config.md I don't think so (yet). Do you have an example of how this would be useful?

stathissideris13:11:46

@borkdude I use hugsql in namespaces that all end in .data and I’d rather not declare all my hugsql-generated functions

borkdude14:11:30

so the vars are foo.data/bar?

borkdude14:11:59

I guess the regex could be "\\.data/.*" in that linter. PR welcome I think

stathissideris14:11:37

by the way, does this look ok to you? :unresolved-symbol {:exclude [(secretary.core [defroute])]}

borkdude14:11:54

could you first make an issue about it with a proposed solution and then a corresponding PR?

borkdude14:11:01

I think that looks ok

borkdude14:11:45

isn't it working?

stathissideris14:11:56

it seems to crash clj-kondo

Unexpected error. Please report an issue.
java.lang.IllegalArgumentException: no conversion to symbol
	at clojure.core$symbol.invokeStatic(core.clj:596)
	at clojure.core$symbol.invoke(core.clj:589)
	at clj_kondo.impl.config$fn__4141$delayed_cfg__4142$fn__4144.invoke(config.clj:187)
	at clojure.lang.ArrayChunk.reduce(ArrayChunk.java:63)
	at clojure.core.protocols$fn__8139.invokeStatic(protocols.clj:136)
	at clojure.core.protocols$fn__8139.invoke(protocols.clj:124)
	at clojure.core.protocols$fn__8099$G__8094__8108.invoke(protocols.clj:19)
	at clojure.core.protocols$seq_reduce.invokeStatic(protocols.clj:31)
	at clojure.core.protocols$fn__8131.invokeStatic(protocols.clj:75)
	at clojure.core.protocols$fn__8131.invoke(protocols.clj:75)
	at clojure.core.protocols$fn__8073$G__8068__8086.invoke(protocols.clj:13)
	at clojure.core$reduce.invokeStatic(core.clj:6828)
	at clojure.core$reduce.invoke(core.clj:6810)
	at clj_kondo.impl.config$fn__4141$delayed_cfg__4142.invoke(config.clj:186)
	at clojure.lang.AFn.applyToHelper(AFn.java:154)
	at clojure.lang.AFn.applyTo(AFn.java:144)
	at clojure.core$apply.invokeStatic(core.clj:665)
	at clojure.core$memoize$fn__6862.doInvoke(core.clj:6353)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clj_kondo.impl.config$fn__4141$fn__4150.invoke(config.clj:195)
	at clj_kondo.impl.namespace$reg_unresolved_symbol_BANG_.invokeStatic(namespace.clj:162)
	at clj_kondo.impl.namespace$reg_unresolved_symbol_BANG_.invoke(namespace.clj:157)
	at clj_kondo.impl.linters$lint_var_usage$iter__5082__5090$fn__5091$iter__5084__5092$fn__5093.invoke(linters.clj:239)
	at clojure.lang.LazySeq.sval(LazySeq.java:42)
	at clojure.lang.LazySeq.seq(LazySeq.java:51)
	at clojure.lang.RT.seq(RT.java:531)
	at clojure.core$seq__5387.invokeStatic(core.clj:137)
	at clojure.core$seq__5387.invoke(core.clj:137)
	at clj_kondo.impl.linters$lint_var_usage$iter__5082__5090$fn__5091.invoke(linters.clj:201)

borkdude14:11:17

@stathissideris ah gotcha:

$ clj -A:clj-kondo --config '{:linters {:unresolved-symbol {:exclude [(secretary.core/defroute)]}}}' --lint - <<< "(require '[secretary.core]) (secretary.core/defroute foo)"
linting took 61ms, errors: 0, warnings: 0

borkdude14:11:30

the vector is for excluding specific symbols within a call

borkdude14:11:47

I'm thinking about deprecating this syntax maybe, since it's a bit odd maybe

stathissideris14:11:51

oooh, sorry, I misread the manual

borkdude14:11:31

no problem. there is an issue for a config validator. once that's there, we should no longer have to bother with this kind of problem

stathissideris14:11:15

so any pointers on where I could start with implementing the new exclusion for the :unresolved-symbol linter?

stathissideris14:11:55

thanks, I’ll have a look!

borkdude14:11:00

if you have a suggestion for a map-based configuration format instead of the vector with lists or symbols, feel free to come up with one as well

borkdude14:11:18

because one problem now is that this config isn't merged with built-in ones (e.g. clojure.test/is)

stathissideris14:11:48

one thing that was a bit unexpected in the config is that each linter seems to expect different (but kinda similar) configs

borkdude14:11:06

Maybe two separate PRs would be nice. Optional of course.

borkdude14:11:44

I think it's good to discuss some alternative formats first before implementing it. But this is another feature really, so let's just focus on the regex first 🙂

borkdude14:11:31

It might be slightly related though, since the regex feature may affect the "ignore in call" exclusion or the symbol itself

stathissideris14:11:25

@borkdude thank you so much by the way, I’m finding bugs with clj-kondo

👍 4
yuhan17:11:30

I had a semi-working branch for that exact feature, could try and polish it up and submit a PR over the weekend!

yuhan17:11:21

My use case was wanting to support Meander macros and ignore all unresolved-symbol warnings for symbols ending with ! and ?

yuhan17:11:58

one odd quirk I found with the regex configurations was how they don't accept actual #"" regex literals and require string literals with double-escaped backslashes

borkdude19:11:36

@qythium that is because EDN doesn't support regexes

borkdude19:11:16

but I do actually support it with edamame (which is a configurable EDN parser), but clj-kondo predates it

eraserhd20:11:54

Since US is on holiday, I finally have space to think about this clj-kondo current directory thing.

eraserhd21:11:21

I think I'm concluding that ideally, I want to lint stdin, but supply the filename somehow so that the clj-kondo can find the config directory.

eraserhd21:11:23

eslint (the first one I checked) does this with --stdin and --stdin-filename options.

👍 4
borkdude21:11:50

@eraserhd - is already there for linting stdin, --stdin-filename would that only be used for finding the config dir? then we could also have --cwd which overrides the current working directory?

eraserhd21:11:09

--stdin-filename would also provide a default for --lang.

borkdude21:11:13

alright, seems good then

eraserhd21:11:15

Oh, to disclose: I'm still pondering. This proposal seems the most "correct", although it requires a bit of rework on the editor part.

eraserhd21:11:52

Some other linters don't support linting stdin. cppcheck being one of them.

borkdude21:11:29

@marc-omorain’s plugin also doesn't use stdin, it uses the raw file + filename, so there it still make sense what we're currently doing

borkdude21:11:04

flycheck (emacs) sets the cwd to the dir of the file being linted

eraserhd21:11:15

huh. That's actually an easy fix. That suggests all linters can find their config in a parent directory?

borkdude21:11:00

ehm, I don't know for all linters

borkdude21:11:14

but I'm happy it works that way

eraserhd21:11:39

But anything that works with flycheck, which is most.

borkdude21:11:42

because I anticipated the same problem for a multi-project git repo, then I checked, and I was happy that it worked in my case (having two .clj-kondo dirs in the same repo)

borkdude21:11:14

@eraserhd aren't you talking from the perspective of kakoune?

eraserhd21:11:57

Well, I'm trying to have a wider perspective and do the "most natural" thing.

borkdude21:11:19

adopting the flycheck behavior requires no changes to clj-kondo

eraserhd21:11:28

Hmm, well changing to the linted file's directory is easy, but it still writes the buffer to a temporary directory passed by absolute path.

borkdude21:11:47

in the intellij setup it's also working like this: the working dir is the file's dir: https://github.com/borkdude/clj-kondo/blob/master/doc/editor-integration.md#intellij-idea

eraserhd21:11:55

Which means the PR I made would not be useful in this case.

borkdude21:11:30

@eraserhd you would of course set the cwd to the dir of the linted file, not the copied tmp file

borkdude21:11:00

but yeah, using the path of the copied tmp file for resolving the config dir is a bit pointless

eraserhd21:11:42

Well, adding a cd to the editor script definitely works.

eraserhd21:11:19

I'm looking at the language-specific checkers in the flycheck org. If very few of them override that working-directory thing, then I'll just make that PR to Kakoune.

eraserhd21:11:30

OK, there are a few, by global GitHub search - elsa, elixir, scons, android, credo.

eraserhd21:11:53

Actually, that seems like a small list, except elixir is important.

borkdude21:11:52

and why does elixir do that?

eraserhd23:11:48

I don't know, but it appears to try to find the "mix directory", which is the project root.