Fork me on GitHub
#clj-kondo
<
2023-12-15
>
Alexander Kouznetsov00:12:09

If two different namespaces refer the same unresolved var, is it expected that results would only contain one warning about it? In my experiments I’m seeing that’s on most occasions it is only on one of the namespaces and only once it was reported on both. What’s more surprising is that even if I lint just one file that contains the problem - it is not reported. Is it because it uses cached linting result somehow?

hiredman00:12:41

we have a number of unresolved vars throughout our code base at work (the vars are there just generated via macros or even in some cases via intern at runtime) and those are reported everywhere they are used across many namespaces

1
1
Alexander Kouznetsov01:12:20

Oh, I see, it was hidden because it was used inside of a macro that was linted with def-catch-all.

👍 1
Noah Bogart01:12:29

need help writing a hook, @U0NCTKEV8?

hiredman01:12:23

It is a whole thing, actually a combination of macros and calling intern, if I recall, where the macros generate the defs from specs in some cases, and that is all in the implementation part of a polylith component and then in the interface part I think it just copies the names using intern

Noah Bogart01:12:11

damn, sounds complicated. If you can share the code, I suspect there's a way to make clj-kondo not yell so much.

borkdude07:12:16

If there aren’t too many, you can also write (declare foo bar) in the defining namespace

hifumi12308:12:11

minor caveat to using declare: it breaks direct linking of the var in question, and in clojurescript, declared vars called as functions will always go through the variadic call route, which can result in degraded performance

borkdude08:12:30

You can surround it with comment, if you have disabled linting in comment that’s on you ;)

borkdude08:12:14

we could also have a way to declare vars about namespaces externally, something like: https://github.com/clj-kondo/clj-kondo/issues/2214#issuecomment-1855046706

hifumi12308:12:13

oh i forgot code in comment forms are linted, too. that's actually a good workaround, because the comment will document vars that get declared by the macro

👍 1
jgdavey17:12:02

Apologies if this has been asked/answered before, but is it possible to write a custom linter that would check if defn args appear on a new line after the function name?

jgdavey17:12:44

This is not a style that everyone uses, but my current work likes this for consistency

borkdude17:12:02

clj-kondo throws away all whitespace before analysis so currently this isn't something it checks

borkdude17:12:21

perhaps this is more something for cljfmt or so

jgdavey17:12:40

👍 Thanks!

Jake Pearson18:12:44

I brought this up in #C8YT051KN a while ago. I believe they were happy to take a PR for this as long as it a user option to enable.

Jake Pearson18:12:51

I haven't had the time to work on it myself.

Noah Bogart18:12:07

This isn’t currently checked but it could be added to #C04SCGV2ATX easily

pithyless18:12:19

FYI, this is supported in the cljstyle formatter. https://github.com/greglook/cljstyle

👍 1
borkdude18:12:57

I mean, theoretically clj-kondo could check if the arg vector is on the next line compared the outer form - it does have that info, but I think it belongs to a formatter (like cljfmt or cljstyle)