This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-08-22
Channels
- # announcements (13)
- # babashka (22)
- # beginners (22)
- # biff (17)
- # calva (6)
- # clerk (20)
- # clj-kondo (25)
- # clj-together (5)
- # clj-yaml (20)
- # cljdoc (16)
- # cljs-dev (1)
- # clojure (42)
- # clojure-brasil (1)
- # clojure-europe (26)
- # clojure-nl (6)
- # clojure-norway (24)
- # clojure-turkiye (3)
- # clojure-uk (5)
- # clojurescript (37)
- # core-async (7)
- # core-logic (2)
- # datalevin (7)
- # datomic (43)
- # events (2)
- # fulcro (7)
- # gratitude (1)
- # hyperfiddle (7)
- # java (7)
- # jobs (3)
- # lsp (4)
- # off-topic (16)
- # pathom (18)
- # polylith (1)
- # portal (27)
- # reitit (4)
- # releases (3)
- # shadow-cljs (47)
- # tools-build (14)
- # tools-deps (16)
- # yamlscript (11)
Hi!
I recently found myself in a situation where I'd like to have some deftest
calls inside of a let
: the namespace contains a huge number of tests and I want to create some local bindings that only apply to a handful of them. Doing deftest
inside of a let
throws clj-kondo off, raising a "unused value" problem for all deftests except for the last one.
I tried addressing this by telling kondo to resolve deftest
as def
(since the linter does not complain about def
) but that didn't have any effect.
A few questions:
• is the unused-value
behavior for deftest
expected?
• if so, should resolving deftest
as def
be a reasonable way to address it?
deftest + unused value was fixed recently, are you using the newest clj-kondo version?
I believe it is the latest version
~/S/e/ellipsus-service ❯❯❯ clj-kondo --version
clj-kondo v2023.07.13
I also observe the same behavior with kondo over lsp:
~/.l/s/n/m/bin ❯❯❯ ./clojure-lsp --version
clojure-lsp 2023.08.06-00.33.37-nightly
clj-kondo 2023.07.14-SNAPSHOT
yeah, makes sense. you can suppress this for now with:
(ns deftest
(:require
[clojure.test :refer [deftest is]]))
#_{:clj-kondo/ignore [:unused-value]}
(let [some-var "some-value"]
(deftest this-one-is-flagged-as-unused
(is (= some-var "some-value")))
(deftest this-one-is-fine
(is (= some-var "some-value"))))
yes! that's what I've done. I also tried the namespace level ignore but to no avail:
(ns deftest-unused-val-repro
{:clj-kondo/ignore [:unused-val]}
(:require
[clojure.test :refer [deftest is]]))
(let [some-var "some-value"]
(deftest this-one-is-flagged-as-unused
(is (= some-var "some-value")))
(deftest this-one-is-fine
(is (= some-var "some-value"))))
ignore works for other linters without any issue, so I'm assuming it's something specific to :unused-value
I included a comment in the same one as it seems related to the original problem as opposed to a completely separate problem (although I'm not familiar enough with kondo's internals to rule that out).
We use some macros from clojure.algo.monads
. I'm currently looking at usage of domonad
, which has two arities
Usage: (domonad steps expr)
(domonad name steps expr)
We currently have this linting as clojure.core/loop
, but loop matches the first arity, and not the second. Is there an "easy" answer here, apart from finding another macro with the same semantics, or writing the config custom?no easy answer, other than: ignoring lint warnings completely or to write a hook for it
probably a hook would not be so difficult, you just expand into a loop expression and let the name drop
That sounds worth trying
This alone took care of 10% of our total warnings!
(defn- domonad-helper
;; This arity of domonad takes a name,
;; but for the purposes of linting,
;; we can just throw that out.
([domonad _ steps expr]
(domonad-helper domonad steps expr))
([_ steps expr]
{:node
(api/list-node
(list
(api/token-node 'let)
steps
expr))}))
(defn domonad [{{children :children} :node}]
(apply domonad-helper children))
..Though I just learned my assumption that name
was unimportant was incorrect. It should be a token that exists, and is usually from another ns.
So now I have many fewer warnings overall, but some false positive "referred but never used" warnings where the name
parameter above had been referred, and this is the only place it's used.
That sounds right. Can you please point me in the direction of how to do that? I just spent a bit of time but didn't turn it up.
It was as simple as that. Thank you again!
(defn- domonad-helper
([_ steps expr]
(list
(api/token-node 'let)
steps
expr))
([_ name steps expr]
(list
(api/token-node 'let)
steps
name
expr)))
(defn domonad [{{children :children} :node}]
{:node (api/list-node (apply domonad-helper children))})