Fork me on GitHub
JP Silva05:07:13

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 Silva05:07:12

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


@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.


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


So, not a bug: expected behavior.

JP Silva05:07:53

got it! thanks!


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 Silva05:07:08

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

JP Silva05:07:08

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


(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)


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.


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 Silva05:07:45

nice! thanks for the tip!


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


Else it has no way of knowing.

JP Silva06:07:11

will take a look, thanks!


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.