clj-kondo 2026-04-13

There's an open PR for this: (not (nil? x)) -> (some? x) (when-not (nil? x) ...) -> (when (some? x) ...) (if-not (nil? x) ...) -> (if (some? x) ...) Personally I'm not completely convinced that either one is always clearer than the other. Maybe leave some feedback in the issue: https://github.com/clj-kondo/clj-kondo/issues/2788

Couldn't the same be said for the (not (empty? x)) -> (seq x) one?

That one is controversial now since clojure 1.12

it was actually relaxed in recent clj-kondo versions

👍 1
Alex Miller (Clojure team) 2026-04-13T13:04:34.892959Z

Shouldn't those use when-some and if-some

➕ 1

@alexmiller those create a binding which might not be needed

if I'm not wrong

Alex Miller (Clojure team) 2026-04-13T13:06:56.750999Z

Ah

> controversial now since clojure 1.12 what's a good documentation of this?

@borkdude to circle back to the OP, I usually prefer the latter forms, i.e. the ones using some? but it can be a style preference thing. Perhaps default to off?

related to this, the not-empty? linter does not warn when we use when-not or if-not maybe it should?

>   clojure -M:clj-kondo/dev --lint - <<< "(when (not (empty? (map identity [1]))) true)"

<stdin>:1:12: warning: Use (seq x) instead of (not (empty? x)) when x is a seq
linting took 40ms, errors: 0, warnings: 1
>   clojure -M:clj-kondo/dev --lint - <<< "(when-not (empty? (map identity [1])) true)"

linting took 33ms, errors: 0, warnings: 0

I discovered that in hot paths (when-not (nil? ...)) is faster than (when (some? ...)) since some? is a var call

😢 1
👌🏿 1

so I'm going to add that warning to the linter docs. it's off by default anyway so it's fine

CLJS does optimize some? to != null