Fork me on GitHub
#clj-kondo
<
2021-09-09
>
Pratik09:09:30

Hello, in my clojure test files I am doing [clojure.test :refer :all] from the imports and clj-kondo is warning me about the deftest, is and testing as unresolved symbol. I have fixed the refer-all warning by excluding it in config.edn but I can’t seem to get rid of the unresolved symbol warnings. It’s probably similar to this issue - https://github.com/clojure-lsp/clojure-lsp/issues/316 but I tried clearing the .clj-kondo/.cache and that didn’t work for me

borkdude09:09:24

@pratikgandhi1997 Are you using clojure-lsp?

borkdude09:09:46

Can you try from the command line: clj-kondo --lint test/your_test_file.clj

borkdude09:09:52

and see if the same error happens

Pratik09:09:02

no, while using this command, it doesn’t throw those errors

borkdude09:09:28

it's a weird issue with clojure-lsp that keeps coming back. please don't throw away any data, since this might be important to get to the root of the problem

borkdude09:09:36

is your code by any chance open source?

Pratik09:09:31

I can try to repro in some test project though

borkdude09:09:49

please do, this would be very valuable

borkdude09:09:04

can you show what is in your .clj-kondo/.cache directory

borkdude09:09:34

Can you show the contents of 2021.08.07-SNAPSHOT (feel free to leave out any corporate specific data)

Pratik09:09:52

just created a new app with lein new app hello and in it’s default core_test.clj file got the same unresolved var error

borkdude09:09:58

can you make a zip archive of this project including the .clj-kondo/.cache ?

borkdude09:09:58

I can't reproduce the issue on my own system. So it would be valuable to have your .zip file

Pratik09:09:01

aah, looks like that newly created project doesn’t have .clj-kondo folder but still I am getting those errors

borkdude09:09:10

that's even weirder

borkdude10:09:07

can you also give the sqlite.db to @UKFSJSM38?

borkdude10:09:12

perhaps this helps

borkdude10:09:26

and you are sure you are not using another linter?

Pratik10:09:39

Sure, I will DM the sqlite.db to @UKFSJSM38

borkdude10:09:02

perhaps just make a .zip file of the whole project including the sqlite.db

👍 2
borkdude10:09:13

and upload it to the issue

borkdude10:09:40

after you've done that, perhaps try again with a .clj-kondo directory

borkdude10:09:51

but please persist the state in a .zip file first

Pratik10:09:40

sure, I will try that. I am using VSCode IDE if that data point helps

borkdude10:09:29

I think I'm getting now what's going wrong....

borkdude10:09:54

this will fix it

borkdude10:09:09

your clojure-lsp doesn't have the built-in clj-kondo caches for clojure.test, etc.

borkdude10:09:40

@UKFSJSM38 feel free to do a similar PR for clj-kondo to move these settings to META-INF

borkdude10:09:54

then clojure-lsp will automatically benefit from this too

borkdude10:09:08

I'll also respond in the issue

ericdallo12:09:58

Good debugging! Yeah, that makes sense now, I'll try fix it for the next release!

ericdallo13:09:31

Fixed on clojure-lsp master @pratikgandhi1997! it should be available on next release

Pratik13:09:02

Awesome! Thanks for the super-quick fix 🙂

🚀 4
lassemaatta13:09:04

I was playing around with the --parallel option to see how much it improved linting performance, but I fail to see any difference. My cpu monitor also reports that only a single cpu core is being utilized while linting. Is this expected or have I messed up something?

lassemaatta13:09:42

I'm doing just clj-kondo --parallel --lint src/.

Noah Bogart13:09:27

how big is the src folder?

lassemaatta13:09:12

very big 🙂

👍 2
lassemaatta13:09:58

not sure if this is a useful data point, but if I lint the src folder from the babashka repo it takes about 520 +/- 5 ms, regardless of --parallel

borkdude13:09:02

@U0178V2SLAY sources are grouped per directory and jar file, this is why you aren't seeing any difference

borkdude13:09:11

this is specifically for linting classpaths

lassemaatta13:09:34

Ah, I see, thanks!

borkdude13:09:40

you could speed it up by linting several different directories separately

borkdude13:09:50

--lint src/dir1:src/dir2 etc

lassemaatta13:09:28

Hmm, I’m almost certain I tried that. I’ll retry later and see if I can spot a difference

borkdude13:09:24

This:

find src -type d | xargs clj-kondo --parallel --lint
vs this:
find src -type d | xargs clj-kondo --lint
seems to make a difference

borkdude13:09:19

strangely just clj-kondo --lint src is faster than both, not sure why

lassemaatta14:09:35

how does clj-kondo handle the situation where you supply "overlapping" directories? e.g. --lint first:first/second:first/second/third:... ?

lassemaatta14:09:01

because I think that what happens if you use find ... , I guess?

borkdude14:09:23

ah I see yes

borkdude14:09:27

clj-kondo doesn't handle that

borkdude14:09:36

it just lints whatever you give it

lassemaatta14:09:10

yeah, I assumed that when I got a bunch of "redefined vars" warnings when trying that find invocation :)

borkdude14:09:31

it could probably filter this out, but I don't think it's very common to do it like this

lassemaatta14:09:37

but back to the original issue: if I supply several sibling folders with --lint src1:src2:..:srcN -> --parallel improves the performance

lassemaatta14:09:53

so I guess it's working as intended, but leveraging the benefits of --parallel when linting a project itself is tricky. which is fine, as the typical performance of clj-kondo is fast enough for most projects

borkdude14:09:22

also when you use --dependencies it will skip already linted .jar files with is another perf optimization

👍 2
Noah Bogart18:09:43

is a hook the best way to indicate that a macro creates multiple defn s?

borkdude18:09:56

depends on the macro

borkdude18:09:15

but with hooks you get the most power, other options work if you're lucky

👍 2
borkdude18:09:37

note that there is now also an "easy" hook option which allows you to write a macro just like you would do it in clojure

❤️ 2
nate18:09:19

is that the :analyze-call stuff?

borkdude18:09:43

that's the "hard" option, the easy option is :macroexpand

👍 2
nate18:09:06

ah cool, I'll check that out