This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-11
Channels
- # announcements (3)
- # aws (3)
- # babashka (79)
- # beginners (105)
- # calva (10)
- # chlorine-clover (22)
- # clj-kondo (12)
- # cljs-dev (39)
- # clojure (52)
- # clojure-europe (1)
- # clojure-spec (15)
- # clojure-uk (12)
- # clojurescript (47)
- # conjure (93)
- # data-science (1)
- # datomic (10)
- # emacs (6)
- # figwheel-main (14)
- # fulcro (30)
- # instaparse (3)
- # kaocha (2)
- # lambdaisland (3)
- # malli (2)
- # meander (6)
- # off-topic (27)
- # pathom (14)
- # perun (1)
- # reagent (15)
- # shadow-cljs (69)
- # slack-help (2)
- # spacemacs (5)
- # test-check (23)
- # vim (9)
Hello all, I´m using Atom with clj-kondo, and, is this used to fix the warning/error from editor too, or only to tell?
Linters just tell you what is wrong. How you fix them is up to you 🙂
To be fair, IntelliJ IDEA's autofixes are numerous and extremely useful on the Java side. The bigger problem however is that there might be several potential fixes to any single issue highlighted by the linter, so choosing just one is quite a task... 🙂 Definitely would be an interesting extension project to create though, that is, read in clj-kondo's linting metadata and provide automatic refactoring actions based on those.
Is the cond->>
expression meant to be supported?
I tried doing something like this, but assoc
gives an lint error:
(cond->> initial-map
(some? x) (assoc :foo bar))
$ clj -e "(cond->> {} (some? 1) (assoc :foo 1))"
Execution error (ClassCastException) at user/eval137 (REPL:1).
clojure.lang.Keyword cannot be cast to clojure.lang.Associative
$ clj-kondo --lint - <<< "(cond->> {} (some? 1) (assoc :foo 1))"
<stdin>:1:30: error: Expected: associative collection or nil, received: keyword.
linting took 10ms, errors: 1, warnings: 0
That seems to be accurate?ah interesting, trying it in repl this works:
(cond-> {:x "foo"}
true (assoc :y "bar"))
result: {:x "foo", :y "bar"}
this doesn’t:
(cond->> {:x "foo"}
true (assoc :y "bar"))
error: class clojure.lang.Keyword cannot be cast to class clojure.lang.Associative
so i guess it’s not a bug in clj-kondo since clojure throws an error too (thanks for checking it, btw). but unless i’m using cond->>
incorrectly looks to be a bug in clojure@alidcastano It's not a bug in Clojure:
user=> (require '[clojure.walk :refer [macroexpand-all]])
nil
user=> (macroexpand-all '(cond->> {:x "foo"} true (assoc :y "bar")))
(let* [G__143 {:x "foo"}] (if true (assoc :y "bar" G__143) G__143))
so cond->
evaluates it to (assoc G__143 :y "bar")
but cond->>
evaluates it to (assoc :y "bar" G__143)
😅
cond->>
is thread last so it threads your expression into the last position in the assoc
call: (assoc :y "bar" data)
which is incorrect usage.
thanks for further clarifying, i do see now that official Clojure docs state that ->>
is the thread last macro. I was reading the cond->>
docs in http://clojuredocs.org and incorrectly inferred this was the only difference: threading does not short after the first expression