clj-kondo

https://github.com/clj-kondo/clj-kondo
lispyclouds 2021-03-15T05:43:59.316400Z

FYI, the static one is meant for OSes like alpine which uses musl. On others is a better idea to use the dynamic one. Static binaries have unforeseen issues unfortunately 😕

raymcdermott 2021-03-15T10:13:42.317300Z

I had a bug a little while ago and not sure if it's something that kondo could detect / warn

raymcdermott 2021-03-15T10:13:48.317600Z

(defn any-evens?
  [coll]
  (reduce (fn [_ x]
            (when (even? x)
              (reduced true))) false coll))

raymcdermott 2021-03-15T10:14:19.317900Z

(any-evens? [2 2])
=> true
(any-evens? [3 3 5])
=> nil

raymcdermott 2021-03-15T10:15:31.318500Z

I wanted false in the second case

raymcdermott 2021-03-15T10:15:52.319100Z

(defn any-evens?
  [coll]
  (reduce (fn [_ x]
            (if (even? x)
              (reduced true)
              false)) false coll))

raymcdermott 2021-03-15T10:16:20.319900Z

gives the correct results ... I know nil is falsey but still

borkdude 2021-03-15T10:16:25.320Z

Not sure how kondo could help here (in general), as returning nil is valid in reduce functions.

raymcdermott 2021-03-15T10:17:51.320300Z

(defn any-evens?
  [coll]
  (reduce (fn [_ x]
            (even? x)) false coll))

raymcdermott 2021-03-15T10:18:06.320700Z

this is also correct, though not as efficient

borkdude 2021-03-15T10:19:04.322Z

Why not (some even? ....) ?

raymcdermott 2021-03-15T10:19:04.322100Z

I'm trying to check whether using reduced and not having another part is flaggable

raymcdermott 2021-03-15T10:20:45.323800Z

sure, it was a lot more complex in reality so I'm showing a trivial example ... I want to get to the fact that incorrect use of reduced ... forgetting to assign the result to the accumulator was actually the issue

raymcdermott 2021-03-15T10:22:06.324100Z

maybe I need a better example