clj-kondo

https://github.com/clj-kondo/clj-kondo
ericdallo 2021-03-02T14:25:28.071800Z

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

ericdallo 2021-03-02T14:25:59.071900Z

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

borkdude 2021-03-02T14:26:12.072100Z

To not annoy you with more info than you probably need

ericdallo 2021-03-02T14:26:30.072300Z

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

ericdallo 2021-03-02T14:26:54.072500Z

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

borkdude 2021-03-02T14:26:56.072700Z

That will also be sufficient on only the first probably?

ericdallo 2021-03-02T14:27:48.072900Z

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

ericdallo 2021-03-02T14:28:10.073100Z

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

borkdude 2021-03-02T14:28:52.073400Z

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

ericdallo 2021-03-02T14:31:40.073600Z

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.

borkdude 2021-03-02T14:32:24.073800Z

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

borkdude 2021-03-02T14:32:53.074Z

what do you mean with "apply the code action"

ericdallo 2021-03-02T14:33:06.074200Z

let me show you a minimal repro

borkdude 2021-03-02T14:33:17.074400Z

love it

borkdude 2021-03-02T14:33:23.074600Z

minimal repros I mean

ericdallo 2021-03-02T14:37:37.074800Z

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

ericdallo 2021-03-02T14:38:18.075Z

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

ericdallo 2021-03-02T14:39:41.075200Z

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

borkdude 2021-03-02T14:42:00.075600Z

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?

borkdude 2021-03-02T14:42:25.075800Z

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

ericdallo 2021-03-02T14:42:57.076Z

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

ericdallo 2021-03-02T14:43:12.076200Z

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

borkdude 2021-03-02T14:43:34.076400Z

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

borkdude 2021-03-02T14:43:51.076600Z

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

ericdallo 2021-03-02T14:43:58.076800Z

to know that we should search for a unresolved ns

ericdallo 2021-03-02T14:44:17.077Z

it' could result in some performance issues

ericdallo 2021-03-02T14:44:30.077200Z

check of require code actions on each alias/foo

borkdude 2021-03-02T14:45:04.077400Z

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

borkdude 2021-03-02T14:45:22.077600Z

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

borkdude 2021-03-02T14:45:32.077800Z

And ignoring only the first will ignore all of them

borkdude 2021-03-02T14:45:42.078Z

Else you would have to ignore all 60 of them

borkdude 2021-03-02T14:46:10.078200Z

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

ericdallo 2021-03-02T14:47:35.078400Z

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?

borkdude 2021-03-02T14:48:00.078800Z

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

borkdude 2021-03-02T14:48:33.079Z

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

borkdude 2021-03-02T14:48:54.079200Z

I'll have to think about this

ericdallo 2021-03-02T14:50:12.079400Z

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

ericdallo 2021-03-02T14:50:39.079600Z

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

borkdude 2021-03-02T14:51:11.079800Z

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.

ericdallo 2021-03-02T14:52:57.080Z

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 🙂

borkdude 2021-03-02T15:01:14.080200Z

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

👍 1
dharrigan 2021-03-02T15:03:40.080500Z

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 🙂

👍 1
borkdude 2021-03-02T15:06:59.080800Z

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

borkdude 2021-03-02T15:07:05.081Z

and personally I like that

danielneal 2021-03-02T16:54:44.082100Z

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>?

borkdude 2021-03-02T16:57:41.082700Z

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

danielneal 2021-03-02T16:57:54.083100Z

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

borkdude 2021-03-02T16:58:15.083600Z

@danieleneal No, should work out of the box

danielneal 2021-03-02T16:59:14.083900Z

I'll try now

danielneal 2021-03-02T17:02:15.084100Z

Perfect 🙂

richiardiandrea 2021-03-02T21:12:02.085500Z

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

2021-03-02T21:15:48.085600Z

Can you use _arg?

richiardiandrea 2021-03-02T21:22:20.085800Z

I could, if that was the only way

richiardiandrea 2021-03-02T21:22:37.086Z

but it feels like a hack

2021-03-02T21:25:27.086200Z

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

richiardiandrea 2021-03-02T21:28:44.086400Z

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

borkdude 2021-03-02T21:29:52.086600Z

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

borkdude 2021-03-02T21:30:19.086800Z

e.g. this question was asked today here: https://clojureverse.org/t/clj-kondo-and-defmulti/7290/3

borkdude 2021-03-02T21:30:33.087100Z

There are already a couple of options for unused-binding

borkdude 2021-03-02T21:30:37.087300Z

We can add another one

borkdude 2021-03-02T21:30:41.087500Z

issue welcome

richiardiandrea 2021-03-02T21:46:37.087700Z

kk thanks @borkdude will open one