This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-06
Channels
- # announcements (58)
- # babashka (43)
- # babashka-sci-dev (22)
- # beginners (8)
- # biff (8)
- # calva (62)
- # circleci (3)
- # clerk (6)
- # clj-kondo (27)
- # cljsrn (9)
- # clojure (61)
- # clojure-austin (4)
- # clojure-conj (3)
- # clojure-europe (11)
- # clojure-losangeles (2)
- # clojure-nl (2)
- # clojure-norway (4)
- # clojure-spain (5)
- # clojure-uk (2)
- # clojurescript (51)
- # data-science (1)
- # datascript (4)
- # emacs (33)
- # events (14)
- # funcool (14)
- # gratitude (13)
- # introduce-yourself (1)
- # jobs (9)
- # lsp (58)
- # malli (23)
- # missionary (31)
- # nextjournal (9)
- # off-topic (35)
- # proletarian (2)
- # re-frame (5)
- # remote-jobs (7)
- # shadow-cljs (2)
- # spacemacs (7)
- # sql (26)
- # testing (12)
- # vim (1)
- # web-security (3)
- # xtdb (2)
I have a macro that is linted-as def
but I don't want it to trigger :clojure-lsp/unused-public-var
- and I would like to avoid putting the :clj-kondo/ignore
directive on each callsite. Is it possible to skip a particular linter at the macro-level?
The macro itself is doing some global mutable state stuff so by definition it is always available as a public var - but obviously clj-kondo doesn't know that...
the linter is implemented by clojure-lsp (the only one). @UKFSJSM38 might have an idea
You have multiple options to ignore that, check the https://clojure-lsp.io/settings/#clojure-lspunused-public-varpage:
.clj-kondo/config.edn
{:linters {:clojure-lsp/unused-public-var {:exclude #{my-ns/foo
my-ns/bar
other-ns
my-func}
:exclude-regex #{"my-integration-tests.*"}
:exclude-when-defined-by #{my-ns/defflow}
:exclude-when-defined-by-regex #{"my.custom/macro-.*"}}}}
So I guess
:clojure-lsp/unused-public-var {:exclude-when-defined-by
#{nosco.views.design-system-utils/defsection}}
And then when I use
(nds/defsection CardsSection ,,,)
I shouldn't get the warning? Because it seems it's not working.@U7PBP4UVA I think it would be best if you made a github repro since my experience is that even if this takes a few minutes to put together, it saves time discussing these issues
:exclude-when-defined-by
won't work since it only works when kondo includes defined-by
analysis, and that only happens in hook level and is defined by user
You will have to:
• use :exclude
as you are aalready using
• create a custom clj-kondo hook and add the defined-by
• Make clj-kondo return the defined-by as the macro name currently is returning :defined-by clojure.core/def
WDYT @U04V15CAJ?
@UKFSJSM38 maybe you can make a PR showing that idea?
I can try later @U04V15CAJ
if you are making a hook you could also emit a usage to suppress the unused public var usage
Seems to do the trick https://github.com/orestis/unused-var-demo/commit/db8fe1b33c86ec83f51ba35be3bba896b8964381
BTW @U04V15CAJ the docs for macroexpand use the wording "recommended" to use the same namespaces/files for the macros, but perhaps it should be changed to "required" instead?