Fork me on GitHub
#clj-kondo
<
2023-09-21
>
Martynas Maciulevičius12:09:47

Hey. What is the best way to suppress linter error from a macro in a library that I don't control? This library is from 2012 but they added a commit recently. I could add a config.edn but is this the best way?

Martynas Maciulevičius12:09:13

This is what the template macro does:

Martynas Maciulevičius12:09:29

There is this issue but the library author closed it: https://github.com/brandonbloom/backtick/issues/8

delaguardo13:09:25

I would add :lint-as {backtick/defquote clojure.core/def} to the .clj-kondo/config.edn

Martynas Maciulevičius13:09:33

This worked. Thanks 💯

delaguardo13:09:38

that wouldn't fix the problem with unresolved symbols but at least template macro will be known to kondo

Martynas Maciulevičius13:09:35

That fixes the underlying outside symbols not being "used" and I think that I can fix the unknown macro by adding one more rule. But the undefined symbols is actually already good.

Martynas Maciulevičius13:09:27

I did this and it fixed the underlying unknown symbols:

{:lint-as
 {backtick/defquote clojure.core/def}
 :linters {:unresolved-symbol {:exclude [(backtick/template)]}}}
But then the template macro itself is said to be undefined. So I added this to the code:
#_{:clj-kondo/ignore [:unresolved-var]}
I'm not sure how to fix it.

delaguardo13:09:45

one way - keep only :lint-as {backtick/defquote clojure.core/def} and then ignore unresolved symbols close to the usage of template:

(let [x 5 v [:a :b]]
  #_{:clj-kondo/ignore [:unresolved-symbol]}
  (b/template {:x ~x, s #{~@v "c" inc}}))

Martynas Maciulevičius13:09:35

I also want to ignore the non-existent-var somehow. But I don't know how to write it. This doesn't work:

{:lint-as
 {backtick/defquote clojure.core/def}
 :linters {:unresolved-symbol {:exclude [(backtick/template)]}
           :unresolved-var {:exclude [(backtick/template)]}}} <------------------------- this

delaguardo13:09:12

why you need to ignore unresolved-var?

Martynas Maciulevičius13:09:28

Because backtick/template gives this:

Diagnostics:
1. Unresolved var: backtick/template [unresolved-var]
So I want to add #_{:clj-kondo/ignore [:unresolved-symbol]} line but add it globally into the config if anybody would want to use this macro. I want it only for the macro and not underlying form :thinking_face: So that I would be able to forget that it existed.

delaguardo13:09:29

that should be fixed by linting backtick/defquote as clojure.core/def at least it works in my playground

Martynas Maciulevičius13:09:50

I added your rule but it's not fixed :thinking_face:

Martynas Maciulevičius13:09:54

this:

{:lint-as
 {backtick/defquote clojure.core/def}
 #_#_:linters {:unresolved-symbol {:exclude [(backtick/template)]}
               :unresolved-var {:exclude [(backtick/template)]}}}
Results in this:

delaguardo13:09:55

hm... here is what I have: in .clj-kondo/config.edn {:lint-as {backtick/defquote clojure.core/def}} and in the source code:

(let [x 5 v [:a :b]]
  #_{:clj-kondo/ignore [:unresolved-symbol]}
  (b/template {:x ~x, s #{~@v "c" inc}}))
rerun your linter to force kondo diagnostics to see if it actually works

Martynas Maciulevičius13:09:22

I restart my IDE and it reloads the config but it doesn't suppress the nonexistent ns var error. And importing [backtick :as b] doesn't help too as b/template gives the same error.

Martynas Maciulevičius13:09:15

I don't add #_{:clj-kondo/ignore [:unresolved-symbol]} into the source code. I want to make it work without it.

Martynas Maciulevičius13:09:38

It works with it but I don't want to use it.

delaguardo13:09:08

to disable unresolved-symbol globally for b/template:

{:lint-as {backtick/defquote clojure.core/def}
 :linters {:unresolved-symbol {:exclude [(backtick/template)]}}}

delaguardo13:09:53

btw, do you know your kondo version?

Martynas Maciulevičius13:09:13

This covers everything:

{:lint-as
 {backtick/defquote clojure.core/def}
 :linters {:unresolved-symbol {:exclude [(backtick/template)]}
           :unresolved-var {:exclude [backtick/template]}}}

Martynas Maciulevičius13:09:03

I upgraded my system yesterday.

clojure-lsp --version
clojure-lsp 2023.08.06-00.28.06
clj-kondo 2023.07.14-SNAPSHOT

borkdude14:09:30

You can lint as syntax quote using a hook, there is one in clerk