clj-kondo

https://github.com/clj-kondo/clj-kondo
JP Silva 2020-07-24T05:15:13.222Z

hi folks, just wanted to check something before submitting a bug. I'm using clj-kondo plugin version v2020.6.21 with visual studio code on MacOS Catalina. Whenever I :require a namespace within my project without providing an alias (`:as`) the first occurrence of a loaded var in the current namespace will result in a "unresolved symbol" error. The subsequent occurrences of the same var won't show the error. Similarly, if the var indeed does not exist, only the first occurrence shows the error and not the subsequent ones. Below is a screenshot of the issue. In this case the some-fn-define-in-bar is defined in the namespace bar.

JP Silva 2020-07-24T05:16:12.222500Z

should I go ahead and submit a bug? Or am I doing something wrong?

seancorfield 2020-07-24T05:20:08.224100Z

@jplfdsilva Kondo only reports the first use of an undeclared var. It doesn't "see" any vars when you use :refer :all, I believe. You either need to use an alias or explicitly :refer the vars by name -- using :refer :all is poor practice.

seancorfield 2020-07-24T05:20:43.224700Z

You'll see there's a warning on :all which will tell you not to do that 🙂

seancorfield 2020-07-24T05:20:59.225Z

So, not a bug: expected behavior.

JP Silva 2020-07-24T05:42:53.225300Z

got it! thanks!

seancorfield 2020-07-24T05:44:22.226400Z

If it's any consolation, we use :refer :all in a lot of our test files and I'm slowly changing that so clj-kondo is happy 🙂

JP Silva 2020-07-24T05:45:08.226800Z

my use case is unit testing where I thought it would make sense to :`refer :all` vars

JP Silva 2020-07-24T05:46:08.227200Z

but if that's how it is, that's ok. thanks for the quick response!

seancorfield 2020-07-24T05:46:46.228Z

(we have 278 occurrences in 266 files -- and only two of those are not test files -- so it'll take us a while to "fix" them all)

seancorfield 2020-07-24T05:47:51.229200Z

I've started doing :as sut for the "system under test" and that's actually quite nice because then I can easily tell what's being tested vs what is just a supporting function: everything being tested is sut/some-function.

seancorfield 2020-07-24T05:48:52.230300Z

For test files that are short and only refer to a couple of functions from the test namespace, I :refer them by name. And I also :refer by name the vars from clojure.test and expectations.clojure.test.

JP Silva 2020-07-24T05:54:45.230500Z

nice! thanks for the tip!

borkdude 2020-07-24T06:23:41.231100Z

@jplfdsilva clj-kondo can resolve the :refer :all-ed vars, but then you need to lint that namespace first.

borkdude 2020-07-24T06:23:50.231300Z

Else it has no way of knowing.

borkdude 2020-07-24T06:24:39.231500Z

See https://github.com/borkdude/clj-kondo#project-setup

JP Silva 2020-07-24T06:29:11.232Z

will take a look, thanks!

borkdude 2020-07-24T06:31:27.232600Z

But in general :refer :all isn't recommended. In places where you think it should be used, you can turn the warning off using config.