Fork me on GitHub
#clj-kondo
<
2021-03-02
>
ericdallo14:03:28

Any reason why clj-kondo warns about only the first unresolved-symbol/namespace of the same symbol?

ericdallo14:03:59

if I have the same unresolved symbol/ns multiple times on the file, clj-kondo only warn the first occurrence

borkdude14:03:12

To not annoy you with more info than you probably need

ericdallo14:03:30

I see, clojure-lsp uses the findings to know if should try to suggest a add-require ns

ericdallo14:03:54

but without the finding it doesn't know that it should seek for a code action

borkdude14:03:56

That will also be sufficient on only the first probably?

ericdallo14:03:48

I don't think so, we get the findings of the current line, we don't iterate over all the findings of the buffer

ericdallo14:03:10

so on a big buffer, I need to search the first occurrence of the unresolved var to apply the code action

borkdude14:03:52

As a user, why would I apply the action on the second unresolved ns instead of the first?

ericdallo14:03:40

Imagine a big buffer, where I has the foo/bar on the start of the buffer and on the end, IMO I want to be able to apply the code action on both places, otherwise I need to find the first occurrence that's how cursive handles that too.

borkdude14:03:24

but the code action only applies something to the ns form. why would you need all places?

borkdude14:03:53

what do you mean with "apply the code action"

ericdallo14:03:06

let me show you a minimal repro

borkdude14:03:23

minimal repros I mean

ericdallo14:03:37

With a code of:

(ns my-ns)

(def some-func []
  (string/split "some-func" #"-"))

;; lots of code

(def other-func []
  (string/split "other-func" #"-"))
I only get a unresolved ns on the first string/split , I'd like to have the same warn on the second split, otherwise that looks a correct code. Also without that finding, there is no way clojure-lsp knows that there is a unresolved ns without that finding

ericdallo14:03:18

so if I try to lsp-execute-code-action on the last string/split , clojure-lsp will suggest no Add missing clojure.string require

ericdallo14:03:41

It just seems odd to me, clj-kondo don't report about all the occurrences of a lint, I know this can be sometimes to much info, but is actually a code that is missing something indeed, just like other IDEs and languages do AFAIK

borkdude14:03:00

But why would I apply the code action on the second one, if I already see that the first one isn't right, at the moment of typing it?

borkdude14:03:25

It's the same for displaying an unresolved var: just once

ericdallo14:03:57

that's the issue, If I copy a lot of code for another buffer/ns I'll need to check from top to bottom

ericdallo14:03:12

in my case, I copied a schema declaration from a clojrue service to another

borkdude14:03:34

Why do you need a finding to infer the alias -> namespace?

borkdude14:03:51

Can't you add this code action to any alias/foo symbol?

ericdallo14:03:58

to know that we should search for a unresolved ns

ericdallo14:03:17

it' could result in some performance issues

ericdallo14:03:30

check of require code actions on each alias/foo

borkdude14:03:04

We could make this an option in clj-kondo, but I would prefer that the user keeps seeing it as it is now

borkdude14:03:22

The reason is that clj-kondo might be wrong and it's really annoying if your buffer is littered with false positives

borkdude14:03:32

And ignoring only the first will ignore all of them

borkdude14:03:42

Else you would have to ignore all 60 of them

borkdude14:03:10

And lsp already indicates there is an error in the buffer using the top-level thing

ericdallo14:03:35

a clj-kondo flag looks good to me as we could have users migrating from other IDEs and having this behavior. I agree that would be a lot of warnings, but all of them correct, right?

borkdude14:03:00

> all of them correct Not always, that's the false positives I referred to

borkdude14:03:33

Even in LSP I would prefer if the display was the same, although you could have all of them as data

borkdude14:03:54

I'll have to think about this

ericdallo14:03:12

I think we can have a hammock time for that, but that is something I always missed from clj-kondo before clojure-lsp 😛 Could be just me, but I prefer a warning if my code is not right and not need to check the whole buffer for the same symbol or something

ericdallo14:03:39

I think if you have a false positive, you need to fix that somehow first, otherwise you will already have some warning somewhere about that

borkdude14:03:11

The issue is, like I already explained: if clj-kondo is wrong, which it can be, then it's irritating to have 60 errors instead of just 1. And right now, you can get rid of those, by only ignoring 1 warning with #_:clj-kondo/ignore. This won't work if we emit all of them. Please put that in an issue.

ericdallo14:03:57

I see, it's a tradeoff indeed, other languages follow this way though, like dart, you can suppress a single warning in a buffer just like #_:clj-kondo/ignore , but still other lines will warn about that. Sure, I'll open a issue later about that, thanks 🙂

borkdude15:03:14

I think this should be a user preference and not a clojure-lsp opinion. We can make toggles for this per linter config

👍 3
dharrigan15:03:40

Actually, I'm the same. I always wondered why it only showed the first but not the others. I wouldn't mind it being a toggle. False positives I can deal with 🙂

👍 3
borkdude15:03:59

I basically did the same what joker did when I implemented this ;)

borkdude15:03:05

and personally I like that

danielneal16:03:44

I'm linting a file that has some xml namespaces created via clojure.data.xml/alias-uri. How do I best fix/suppress the unresolved namespace errors for ::<alias>/<keyword>?

borkdude16:03:41

@danieleneal I just fixed this in the latest version, released Sunday

danielneal16:03:54

wow! That's great - how does it work, do I need to do anything special in config?

borkdude16:03:15

@danieleneal No, should work out of the box

danielneal16:03:14

I'll try now

danielneal17:03:15

Perfect 🙂

richiardiandrea21:03:02

Hi there, is there a way to tell clj-kondo not to warn me in case of defmulti "unused" bindings? I basically like to leave them there as part of the documentation of the defmulti

mynomoto21:03:48

Can you use _arg?

richiardiandrea21:03:20

I could, if that was the only way

richiardiandrea21:03:37

but it feels like a hack

mynomoto21:03:27

I think it's the usual convention. Not sure if there is a config specific for defmulti.

richiardiandrea21:03:44

I see, thanks, it might be worth an issue but I am going to wait to see if borkdude is around

borkdude21:03:52

This question has come up more than a couple of times and I think it's good to make an option for this

borkdude21:03:33

There are already a couple of options for unused-binding

borkdude21:03:37

We can add another one

borkdude21:03:41

issue welcome

richiardiandrea21:03:37

kk thanks @U04V15CAJ will open one