Skip to content

Commit f4d69e0

Browse files
committed
Use 'when' instead of 'if' for single branches
Recommended by the Clojure Style Guide.
1 parent 622e150 commit f4d69e0

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

cljfmt/src/cljfmt/core.cljc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,13 @@
225225
(some-> zloc z/down ns-token?)))
226226

227227
(defn- indent-matches? [key sym]
228-
(if (symbol? sym)
228+
(when (symbol? sym)
229229
(cond
230230
(symbol? key) (= key sym)
231231
(pattern? key) (re-find key (str sym)))))
232232

233233
(defn- token-value [zloc]
234-
(if (token? zloc) (z/sexpr zloc)))
234+
(when (token? zloc) (z/sexpr zloc)))
235235

236236
(defn- reader-conditional? [zloc]
237237
(and (reader-macro? zloc) (#{"?" "?@"} (-> zloc z/down token-value str))))
@@ -260,14 +260,14 @@
260260

261261
(defn- inner-indent [zloc key depth idx context]
262262
(let [top (nth (iterate z/up zloc) depth)]
263-
(if (and (or (indent-matches? key (fully-qualified-symbol zloc context))
264-
(indent-matches? key (remove-namespace (form-symbol top))))
265-
(or (nil? idx) (index-matches-top-argument? zloc depth idx)))
263+
(when (and (or (indent-matches? key (fully-qualified-symbol zloc context))
264+
(indent-matches? key (remove-namespace (form-symbol top))))
265+
(or (nil? idx) (index-matches-top-argument? zloc depth idx)))
266266
(let [zup (z/up zloc)]
267267
(+ (margin zup) (indent-width zup))))))
268268

269269
(defn- nth-form [zloc n]
270-
(reduce (fn [z f] (if z (f z)))
270+
(reduce (fn [z f] (when z (f z)))
271271
(z/leftmost zloc)
272272
(repeat n z/right)))
273273

@@ -280,8 +280,8 @@
280280
true)))
281281

282282
(defn- block-indent [zloc key idx context]
283-
(if (or (indent-matches? key (fully-qualified-symbol zloc context))
284-
(indent-matches? key (remove-namespace (form-symbol zloc))))
283+
(when (or (indent-matches? key (fully-qualified-symbol zloc context))
284+
(indent-matches? key (remove-namespace (form-symbol zloc))))
285285
(let [zloc-after-idx (some-> zloc (nth-form (inc idx)))]
286286
(if (and (or (nil? zloc-after-idx) (first-form-in-line? zloc-after-idx))
287287
(> (index-of zloc) idx))

0 commit comments

Comments
 (0)