This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-05-14
Channels
- # admin-announcements (1)
- # announcements (28)
- # babashka (9)
- # beginners (32)
- # biff (1)
- # calva (1)
- # clj-kondo (26)
- # clj-otel (52)
- # cljs-dev (2)
- # clojure (41)
- # clojure-europe (23)
- # clojure-korea (7)
- # clojure-nl (1)
- # clojure-norway (39)
- # clojure-uk (4)
- # community-development (10)
- # core-typed (9)
- # cursive (2)
- # datahike (8)
- # events (1)
- # helix (10)
- # kaocha (5)
- # malli (14)
- # missionary (4)
- # off-topic (42)
- # pedestal (1)
- # reagent (3)
- # releases (5)
- # shadow-cljs (33)
- # squint (18)
- # tools-build (8)
- # xtdb (17)
My macro can be used inside itself. I'm writing a hook for it. And I already implemented an inner walk so that when the outer macro is linter is expands the inner ones as well. But my only remaining issue is if the inner macro calls are aliased, I don't know how to equal them? Currently I do (api/sexpr token) and check if it's equal to the qualified and unqualified. But my guess is that returns alias/name and not the expanded form. What should I do?
I don't think you have to let the hook do the work of expanding the inner calls. Why not let clj-kondo do that for you if you just expand like you would in a normal macro
Maybe I did something wrong. But my macro also needs to expands the inner macros. I think it's because I need to expand the inside ones first.
Another issue I have is I get: unresolved symbol defn!
for some reason. My hook does convert it to a defn
, but I would not expect clj-kondo to think the symbol is gone? Or am I supposed to also return a declare defn!
or something to teach it?
This only happens when using :refer :all
Hum, I ran:
> $ clj-kondo --lint "$(clojure -Spath)" --copy-configs --skip-lint
> $ clj-kondo --lint $(clojure -Spath) --dependencies --parallel
Explicitly (instead of relying on clojure-lsp) and the unresilved symbol defn!
disappeared.
Looks like the stale clj-kondo cache issue.
Has anyone considered a lint warning for the following form:
(str "string literal")
If not, is there interest?Heh! I just came across something similar in a PR: (str (format fmt-str arg1 arg2))
I've come across it quite a few times over the years. Had been on my list to raise for a while. Seems somewhat consistent with the fact kondo lints :single-logical-operand
, :single-operand-comparison
and :redundant-call
imo. It could even be added to the latter, no?
ok, I pushed a POC to the branch redundant-call-string
:
$ clj -M:clj-kondo/dev --lint - --config '{:linters {:redundant-call {:level :warning}}}' <<< '(str "foo") (str (format "hello"))'
<stdin>:1:6: warning: Argument to str is already a string
<stdin>:1:18: warning: Argument to str is already a string
linting took 38ms, errors: 0, warnings: 2


Looks good. One bit of feedback: "Argument to str is already a string"
is maybe a bit subtle, because multiple args are often already strings. It's the fact that a single string is provided that is a lint warning. Maybe "Single argument to str is already a string"
is a bit clearer?
yeah this is pretty much a hack in the type system right now, the proper thing to do would be to report a redundant call at the location of the str
call
Better now:
$ clj -M:clj-kondo/dev --lint - --config '{:linters {:redundant-call {:level :warning}}}' <<< '(str "foo") (str (format "hello"))'
<stdin>:1:1: warning: Single argument to str already is a string
<stdin>:1:13: warning: Single argument to str already is a string
linting took 39ms, errors: 0, warnings: 2

Thanks @U04V15CAJ