Open ikappaki opened 1 year ago
This happens because this linter is a clj-kondo custom linter used in :custom-lint-fn
, I think clj-kondo should support that but not sure how hard would be, WDYT @borkdude ? (I can't recall or find a issue related to that if already exists)
I think it might be better to do this as :config-in-ns
and then the lsp linter itself can look into the config?
I was trying to avoid having more custom lint logic on lsp side, since other clj-kondo users can use custom-lint-fn, if they apply a reg-finding!
they would face the same issue not being able to ns meta config or need to manually read/handle :config-in-ns, right?
Makes sense, but the reg-finding
is called without any reference to the namespace, so how would clj-kondo know how to suppress that lint warning?
Good point, maybe we could add a extra arg to that reg-finding?
I don't see the complete picture of this yet, but I'm open to an experimental PR to explore that idea
Hi @ericdallo,
is there anything I can help you out with this to get it moving?
thanks
@ikappaki my idea is: currently clj-kondo exposes a :custom-lint-fn
arg that clojure-lsp passes during every lint, as arg of that function, clj-kondo passes reg-findin!
, which currently clojure-lsp calls it here, I was thinking if clj-kondo could receive on that map arg the :ns
and internally check the ns config as it does for other linters
@borkdude is it correct that clj-kondo collects ns metadata config while a file is being read, uses it while processing that file, and then discards it?
If so, your plan sounds hard @ericdallo. Consider the following two files:
;; using.clj
(ns using
(:require [defining]))
defining/a-var
;; defining.clj
(ns defining
{:clj-kondo/config '{:linters {:clojure-lsp/unused-public-var {:level :off}}}})
(def a-var 1)
If the user deletes the var-usage from using.clj
, then the var-definition in defining.clj
is unused.
However, in this situation we ask clj-kondo to analyze the contents of using.clj
, but not defining.clj
. During the analysis run clj-kondo won't ever see the ns metadata config from defining.clj
, the config which it needs to decide whether to include lint on a var defined in the defining
ns.
It should have seen that config in a previous run, whenever defining.clj
was last analyzed, but that means you need to give clj-kondo a durable cache of namespace -> config (or maybe [filename namespace] -> config) which it can re-use in later runs. It's not impossible, just sounds like quite a lot of work.
I wish I had a better suggestion about how to implement this, but unfortunately I don't. Just pointing out problems 😛
For this situation it's preferred to use :config-in-ns
Describe the bug Can't turn off
:clojure-lsp/unused-public-var
level in namespace metadata under the:clj-kondo/config
keyTo Reproduce
src/exp.clj
file with an unused var while turning theunused-public-var
linter off.(def a nil)
$ clojure-lsp diagnostics [100%] Project analyzed
Finding diagnostics... src\exp.clj:3:5: info: [clojure-lsp/unused-public-var] Unused public var 'exp/a'
but is not reported as expected when the unresolved linter is turned off, i.e. the
clj-kondo/config
works forunresolved-symbol
but not forunused-public-var