This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-09-21
Channels
- # announcements (12)
- # architecture (26)
- # beginners (165)
- # biff (19)
- # calva (25)
- # circleci (2)
- # clj-kondo (25)
- # clojure (70)
- # clojure-dev (17)
- # clojure-europe (37)
- # clojure-nl (1)
- # clojure-norway (22)
- # clojure-spec (10)
- # clojure-sweden (1)
- # clojure-uk (24)
- # clojurescript (10)
- # clr (9)
- # cursive (17)
- # data-science (2)
- # datahike (1)
- # deps-new (1)
- # dev-tooling (3)
- # emacs (3)
- # events (7)
- # helix (10)
- # honeysql (1)
- # hugsql (3)
- # humbleui (3)
- # hyperfiddle (30)
- # introduce-yourself (3)
- # jobs (1)
- # malli (4)
- # music (1)
- # off-topic (3)
- # pathom (3)
- # polylith (6)
- # portal (7)
- # re-frame (16)
- # reitit (3)
- # releases (3)
- # remote-jobs (1)
- # shadow-cljs (23)
- # xtdb (14)
I'm seeing this unused public var highlighting in calva. It probably comes from the lsp. Apparently you can use undeclared vars in defmacro because this code works fine. But some part of the machinery here thinks you can't.
I think some part of the machinery just advices you to not do that. Clojure code is read top to bottom. But, yes, maybe a better error message would be good for this case.
Clojure is read top to bottom but the macro is not expanded there so there's not a problem.
Humans read Clojure top to bottom is what I meant. But yes, much because the Clojure reader does it. I’d say it’s convention to order the code like that even in cases where the compiler doesn’t need it.
@U05H8N9V0HZ in .clj-kondo/config.edn
merge this {:linters {:clojure-lsp/unused-public-var {:level :off}}}
and the blue squiglies will no longer bother you ;)
That’s not the issue here, though, is it? The argument made is that the var is used. (I disagree slightly, but anyway). What say @UKFSJSM38 and @U04V15CAJ?
unused public var is a linter implemented by clojure-lsp, so I'll defer to @UKFSJSM38 :)
FWIW I also have this linter disabled, I find the reference counter next to my vars enough information
Somehow it started working again and this example works for me:
(defmacro foo []
`(stringify-keys))
(defn stringify-keys [m]
(reduce-kv (fn [m k v]
(assoc! m (str k) v)) (transient {}) m))
me too, a minimal repro would be nie @U05H8N9V0HZ
Got it:
The :use
seems to be involved.
Could't repro without that.
spooky action at a distance? 🙂
clj-kondo is a static analyzer which very much relies on the ns form, sometimes use works well, but sometimes it doesn't...
use also doesn't exist in ClojureScript btw, it's probably best to just avoid it when you can
Here is a clojure community guide with some recommendations https://github.com/bbatsov/clojure-style-guide#prefer-require-over-use
I only use it for dev libs I intend to remove later. The yellow highlighting is a nice reminder to remove it.