Fork me on GitHub
#calva
<
2023-05-04
>
jonoflayham10:05:11

Hi, all! If clj-kondo is suggesting a change somewhere in my source code other than where the cursor currently is, how do I accept the suggestion, either with the mouse or (once I’ve clicked the suggestion site) with a keystroke? I’m on a Mac, and control-space / command-dot don’t do the trick. (I’m new to VS Code, so my question may be a VS Code question rather than a Calva one.)

pez10:05:44

Not sure I follow. But command-dot (quick-fix) is the way to get to know what fixes are available. If you don’t see any fixes for the problem, then probably there is none. I have a feeling I am missing what the problem is, though…

jonoflayham10:05:10

Sorry - pics would be better! clj-kondo suggests, but quick-fix doesn’t know about the suggestion.

pez10:05:25

It knows as much as you can suppress it. 😃 Jokes aside, this means that clojure-lsp (which provides the linting and the quick-fixes) does not have a quick-fix. You’re supposed to fix this manually (or suppress the warning, or live with the squiggle).

pez10:05:16

Maybe the wording of the lint message is what makes you think there is a fix you don’t find?

Stuart16:05:10

I think instead it maybe wants (seq ...) Rather than (not (empty?))

skylize17:05:25

Yes. Idiomatic style is to check for emptiness of a collection using (seq foo), which returns nil if the collection is empty, which is falsey (equivalent to false as a conditional). clj-kondo is telling you that you are using a non-idiomatic style.

skylize17:05:22

(seq foo) returns a sequenced collection if not empty, or nil if it is empty. Your code can be rewritten as

(filter seq (map process collection))

skylize18:05:39

Or as

(remove empty? (map process collection))
which I think is a bit clearer about the intention (and preserves the type of the tested collections).

skylize18:05:56

I might suggest to Eric Dallo to add this as a quick fix. Except it only takes a small amount of experience before you will simply quit looking toward (not (empty? foo)) and not need a quick fix for it.

pez18:05:11

My point was that since the message is worded like a quick fix could be worded, maybe that created the expectation that there would be some way to get it done?

skylize18:05:58

Agreed. Reasonable confusion

jonoflayham06:05:51

Yes, that was my problem - I was assuming that since a suggestion was being made, a corresponding quick fix would also be offered. Thanks for the clarifications, anyway!

🙏 2
skylize12:05:57

The message reads like a suggestion, but is actually the error message for that particular clj-kondo linting rule. It's saying "to satisfy this rule, you must use seq idiom." Quick fixes are implementd by clojure-lsp. But the lines between clj-kondo and LSP can definitely seem pretty fuzzy, especially when new to Calva.