clj-kondo

borkdude 2026-04-13T09:18:53.941469Z

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

imre 2026-04-13T12:57:08.837569Z

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

borkdude 2026-04-13T12:57:46.378129Z

That one is controversial now since clojure 1.12

borkdude 2026-04-13T12:58:04.672059Z

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
imre 2026-04-13T13:05:15.668949Z

@alexmiller those create a binding which might not be needed

imre 2026-04-13T13:05:26.300459Z

if I'm not wrong

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

Ah

imre 2026-04-13T13:07:11.113429Z

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

imre 2026-04-13T13:08:34.396449Z

@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?

borkdude 2026-04-13T13:12:15.705719Z

@imre https://github.com/clj-kondo/clj-kondo/issues/1743

🙏 1
imre 2026-04-13T13:12:48.966279Z

hah

jramosg 2026-04-15T05:38:04.579309Z

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

borkdude 2026-06-16T14:58:47.233559Z

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

😢 1
👌🏿 1
borkdude 2026-06-16T14:59:01.425559Z

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

borkdude 2026-06-16T15:00:11.481209Z

CLJS does optimize some? to != null