This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-11
Channels
- # aleph (7)
- # announcements (5)
- # beginners (58)
- # calva (20)
- # cider (10)
- # clj-kondo (4)
- # cljfx (5)
- # cljsrn (7)
- # clojure (29)
- # clojure-europe (11)
- # clojure-mexico (1)
- # clojure-norway (26)
- # clojure-uk (9)
- # clojurescript (1)
- # cursive (31)
- # datahike (22)
- # datomic (12)
- # duct (3)
- # fulcro (28)
- # helix (35)
- # hyperfiddle (28)
- # lsp (4)
- # malli (8)
- # midje (3)
- # music (2)
- # nbb (9)
- # nrepl (20)
- # off-topic (36)
- # polylith (3)
- # shadow-cljs (47)
- # sql (2)
- # testing (7)
- # vim (17)
- # xtdb (7)
Not sure if this is a Calva thing or a clj-kondo thing, (and I'm pretty certain it's a "me" thing) but I don't understand why, when I have code like this
(ns core
(:require [clojure.string :as str :refer [split-lines split trim]]))
...
(defn load-input-lines [file]
(str/split-lines (load-input-raw file)))
I get a problem telling me
#'clojure.string/split-lines is referred but never used
Sorry, I missed a control. Trying to learn all the Calva shortcuts is getting to me 🙂
Ah. You're getting this message because the :refer
for split-lines
wasn't necessary here since you used the alias
I think this is actually the crux of my question. kondo is clearly trying to help me here, but i can't quite grasp what it's telling me.
if you write (split-lines ...)
the message would go away - does that make sense to you?
I tend to use either an namespace alias or refers, preferring aliasing the ns. And in case of clojure.string
I always alias it and always use string
as the alias. I know str
is ubiquitous, but there is a function named str
that does not live in this ns, and I like to be able to distinguish them by the name only.
there seem so many ways to bring things into scope. Things work, but maybe aren't the right way. This is why I really like having a tool like kondo, and why I like to understand what it's telling me.
Is there any penalty in pulling in all of, say clojure.string
rather than specifying what you need?
@U0132B7P7C6 no penalty
In that case then, I like require :as
and specify the prefix in the code. That seems simplest and clearest to me.
A related note is that sometimes you can get away without the require
and use the fully qualified name directly. As long as the namespace is loaded this will work. However, it is bad practice as your program can stop working by the removal of some seemingly unrelated file. clj-kondo helps avoiding this mistake.