Liking cljdoc? Tell your friends :D

Lint

lint/apply-str

EnabledAdded
true0.1

Check for round-about clojure.string/reverse.

Examples

; bad
(apply str x)

; good
(clojure.string/join x)

lint/apply-str-interpose

EnabledAdded
true0.1

Check for round-about str/join.

Examples

; bad
(apply str (interpose "," x))

; good
(clojure.string/join "," x)

lint/apply-str-reverse

EnabledAdded
true0.1

Check for round-about clojure.string/reverse.

Examples

; bad
(apply str (reverse x))

; good
(clojure.string/reverse x)

lint/assoc-assoc

EnabledAdded
true0.1

Layering assoc calls are hard to read. assoc-in is known and idiomatic.

Examples

; bad
(assoc coll :key1 (assoc (:key2 coll) :key2 new-val))
(assoc coll :key1 (assoc (coll :key2) :key2 new-val))
(assoc coll :key1 (assoc (get coll :key2) :key2 new-val))

; good
(assoc-in coll [:key1 :key2] new-val)

lint/assoc-fn

EnabledAdded
true0.1

assoc-ing an update with the same key are hard to read. update is known and idiomatic.

Examples

; bad
(assoc coll :a (+ (:a coll) 5))
(assoc coll :a (+ (coll :a) 5))
(assoc coll :a (+ (get coll :a) 5))

; good
(update coll :a + 5)

lint/body-unquote-splicing

EnabledAdded
true0.1

A macro that nests an unquote-splicing in a macro with a & body can lead to subtle hard to debug errors. Better to wrap the unquote-splicing in a do to force it into 'expression position'.

Examples

# bad
`(binding [max mymax] ~@body)

# good
`(binding [max mymax] (let [res# (do ~@body)] res#))

lint/conj-vector

EnabledAdded
true0.1

vector is succinct and meaningful.

Examples

; bad
(conj [] :a b {:c 1})

; good
(vector :a b {:c 1})

lint/divide-by-one

EnabledAdded
true0.1

Checks for (/ x 1).

Examples

; bad
(/ x 1)

; good
x

lint/dorun-map

EnabledAdded
true0.1

run! uses reduce which non-lazy.

Examples

; bad
(dorun (map println (range 10)))

; good
(run! println (range 10))

lint/dot-class-method

EnabledAdded
true0.1

Using the Obj/staticMethod form maps the method call to Clojure's natural function position.

Examples

; bad
(. Obj staticMethod args)

; good
(Obj/staticMethod args)

lint/dot-obj-method

EnabledAdded
true0.1

Using the .method form maps the method call to Clojure's natural function position.

Examples

; bad
(. obj method args)

; good
(.method obj args)

lint/duplicate-field-name

EnabledAdded
true0.1

deftype and defrecord will throw errors if you define multiple fields with the same name, but it's good to catch these things early too.

Examples

# bad
(defrecord Foo [a b a])

# good
(defrecord Foo [a b c])

Reference

  • [https://guide.clojure.style/#naming-conversion-functions]

lint/eq-false

EnabledAdded
true0.1

false? exists so use it.

Examples

; bad
(= false x)
(= x false)

; good
(false? x)

lint/eq-nil

EnabledAdded
true0.1

nil? exists so use it.

Examples

; bad
(= nil x)
(= x nil)

; good
(nil? x)

lint/eq-true

EnabledAdded
true0.1

true? exists so use it.

Examples

; bad
(= true x)
(= x true)

; good
(true? x)

lint/eq-zero

EnabledAdded
true0.1

zero? exists so use it.

Examples

; bad
(= 0 num)
(= num 0)
(== 0 num)
(== num 0)

; good
(zero? num)

lint/filter-complement

EnabledAdded
true0.1

Check for (filter (complement pred) coll)

Examples

; bad
(filter (complement even?) coll)

; good
(remove even? coll)

lint/filter-vec-filter

EnabledAdded
true0.1

filterv is preferable for using transients.

Examples

; bad
(vec (filter pred coll))

; good
(filterv pred coll)

lint/first-first

EnabledAdded
true0.1

ffirst is succinct and meaningful.

Examples

; bad
(first (first coll))

; good
(ffirst coll)

lint/first-next

EnabledAdded
true0.1

fnext is succinct and meaningful.

Examples

; bad
(first (next coll))

; good
(fnext coll)

lint/fn-wrapper

EnabledAdded
true0.1

Avoid wrapping functions in pass-through anonymous function defitions.

Examples

; bad
(fn [num] (even? num))

; good
even?

; bad
(let [f (fn [num] (even? num))] ...)

; good
(let [f even?] ...)

Reference

  • [https://guide.clojure.style/#no-useless-anonymous-fns]

lint/if-else-nil

EnabledAdded
true0.1

Idiomatic if defines both branches. when returns nil in the else branch.

Examples

; bad
(if (some-func) :a nil)

; good
(when (some-func) :a)

Reference

  • [https://guide.clojure.style/#when-instead-of-single-branch-if]

lint/if-let-else-nil

EnabledAdded
true0.1

Idiomatic if-let defines both branches. when-let returns nil in the else branch.

Examples

; bad
(if-let [a 1] a nil)

; good
(when-let [a 1] a)

lint/if-nil-else

EnabledAdded
true0.1

Idiomatic if defines both branches. when-not returns nil in the truthy branch.

Examples

; bad
(if (some-func) nil :a)

; good
(when-not (some-func) :a)

lint/if-not-both

EnabledAdded
true0.1

if-not exists, so use it.

Examples

; bad
(if (not x) y z)

; good
(if-not x y z)

Reference

  • [https://guide.clojure.style/#if-not]

lint/if-not-do

EnabledAdded
true0.1

when-not already defines an implicit do. Rely on it.

Examples

; bad
(if-not x (do (println :a) (println :b) :c))

; good
(if-not x (println :a) (println :b) :c)

lint/if-not-not

EnabledAdded
true0.1

Two nots cancel each other out.

Examples

; bad
(if-not (not x) y z)

; good
(if x y z)

lint/if-same-truthy

EnabledAdded
true0.1

or exists so use it lol.

Examples

; bad
(if x x y)

; good
(or x y)

lint/into-literal

EnabledAdded
true0.1

vec and set are succinct and meaningful.

Examples

; bad
(into [] coll)

; good
(vec coll)

; bad
(into #{} coll)

; good
(set coll)

lint/let-do

EnabledAdded
true0.1

let has an implicit do, so use it.

Examples

; bad
(let [a 1 b 2] (do (println a) (println b)))

; good
(let [a 1 b 2] (println a) (println b))

lint/let-if

EnabledAdded
true0.1

if-let exists so use it. Suggestions can be wrong as there's no code-walking to determine if result binding is used in falsy branch.

Examples

; bad
(let [result (some-func)] (if result (do-stuff result) (other-stuff)))

; good
(if-let [result (some-func)] (do-stuff result) (other-stuff))

Reference

  • [https://guide.clojure.style/#if-let]

lint/let-when

EnabledAdded
true0.1

when-let exists so use it.

Examples

; bad
(let [result (some-func)] (when result (do-stuff result)))

; good
(when-let [result (some-func)] (do-stuff result))

Reference

  • [https://guide.clojure.style/#when-let]

lint/loop-do

EnabledAdded
true0.1

loop has an implicit do. Use it.

Examples

; bad
(loop [] (do (println 1) (println 2)))

; good
(loop [] (println 1) (println 2))

lint/loop-empty-when

EnabledAdded
true0.1

Empty loops with nested when can be while.

Examples

; bad
(loop [] (when (some-func) (println 1) (println 2) (recur)))

; good
(while (some-func) (println 1) (println 2) (recur))

lint/mapcat-apply-apply

EnabledAdded
true0.1

Check for (apply concat (apply map x y))

Examples

; bad
(apply concat (apply map x y))

; good
(mapcat x y)

lint/mapcat-concat-map

EnabledAdded
true0.1

Check for (apply concat (map x y z))

Examples

; bad
(apply concat (map x y))
(apply concat (map x y z))

; good
(mapcat x y)
(mapcat x y z)

lint/minus-one

EnabledAdded
true0.1

Checks for simple -1 that should use clojure.core/dec.

Examples

; bad
(- x 1)

; good
(dec x)

lint/minus-zero

EnabledAdded
true0.1

Checks for x - 0.

Examples

; bad
(- x 0)

; good
x

lint/missing-body-in-when

EnabledAdded
true0.1

when calls should have at least 1 expression after the condition.

Examples

; bad
(when true)
(when (some-func))

; good
(when true (do-stuff))
(when (some-func) (do-stuff))

lint/multiply-by-one

EnabledAdded
true0.1

Checks for (* x 1).

Examples

; bad
(* x 1)
(* 1 x)

; good
x

lint/multiply-by-zero

EnabledAdded
true0.1

Checks for (* x 0).

Examples

; bad
(* x 0)
(* 0 x)

; good
0

lint/neg-checks

EnabledAdded
true0.1

neg? exists so use it.

Examples

; bad
(< num 0)
(> 0 num)

; good
(neg? x)

lint/nested-addition

EnabledAdded
true0.1

Checks for simple nested additions.

Examples

; bad
(+ x (+ y z))
(+ x (+ y z a))

; good
(+ x y z)
(+ x y z a)

lint/nested-multiply

EnabledAdded
true0.1

Checks for simple nested multiply.

Examples

; bad
(* x (* y z))
(* x (* y z a))

; good
(* x y z)
(* x y z a)

lint/next-first

EnabledAdded
true0.1

nfirst is succinct and meaningful.

Examples

; bad
(next (first coll))

; good
(nfirst coll)

lint/next-next

EnabledAdded
true0.1

nnext is succinct and meaningful.

Examples

; bad
(next (next coll))

; good
(nnext coll)

lint/not-empty?

EnabledAdded
true0.1

seq returns nil when given an empty collection. empty? is implemented as (not (seq coll)) so it's best and fastest to use seq directly.

Examples

; bad
(not (empty? coll))

; good
(seq coll)

lint/not-eq

EnabledAdded
true0.1

not= exists, so use it.

Examples

; bad
(not (= num1 num2))

; good
(not= num1 num2)

Reference

  • [https://guide.clojure.style/#not-equal]

lint/not-nil?

EnabledAdded
true0.1

some? exists so use it.

Examples

; bad
(not (nil? x))

; good
(some? x)

lint/not-some-pred

EnabledAdded
true0.1

not-any? is succinct and meaningful.

Examples

; bad
(not (some even? coll))

; good
(not-any? even? coll)

lint/plus-one

EnabledAdded
true0.1

Checks for simple +1 that should use clojure.core/inc.

Examples

; bad
(+ x 1)
(+ 1 x)

; good
(inc x)

lint/plus-zero

EnabledAdded
true0.1

Checks for x + 0.

Examples

; bad
(+ x 0)
(+ 0 x)

; good
x

lint/pos-checks

EnabledAdded
true0.1

pos? exists so use it.

Examples

; bad
(< 0 num)
(> num 0)

; good
(pos? x)

lint/redundant-call

EnabledAdded
true0.1

A number of core functions take any number of arguments and return the arg if given only one. These calls are effectively no-ops, redundant, so they should be avoided.

Current list of clojure.core functions this linter checks:

  • ->, ->>
  • cond->, cond->>
  • some->, some->>
  • comp, partial, merge

Examples

; bad
(-> x)
(->> x)
(cond-> x)
(cond->> x)
(some-> x)
(some->> x)
(comp x)
(partial x)
(merge x)

; good
x

lint/take-repeatedly

EnabledAdded
true0.1

repeatedly has an arity for limiting the number of repeats with take.

Examples

; bad
(take 5 (repeatedly (range 10))

; good
(repeatedly 5 (range 10))

lint/thread-macro-one-arg

EnabledAdded
true0.1

Threading macros require more effort to understand so only use them with multiple args to help with readability.

Examples

; bad
(-> x y)
(->> x y)

; good
(y x)

; bad
(-> x (y z))

; good
(y x z)

; bad
(->> x (y z))

; good
(y z x)

lint/tostring

EnabledAdded
true0.1

Convert (.toString) to (str).

Examples

; bad
(.toString x)

; good
(str x)

lint/try-splicing

EnabledAdded
true0.1

A macro that wraps a splicing unquote in a try-catch or try-finally can lead to subtle hard to debug errors. Better to wrap the splicing unquote in a do to force it into 'expression position'.

Examples

# bad
`(try ~@body (finally :true))

# good
`(try (do ~@body) (finally :true))

lint/update-in-assoc

EnabledAdded
true0.1

update-in-ing an assoc with the same key are hard to read. assoc-in is known and idiomatic.

Examples

; bad
(update-in coll [:a :b] assoc 5)

; good
(assoc-in coll [:a :b] 5)

lint/useless-do

EnabledAdded
true0.1

A single item in a do is a no-op.

Examples

; bad
(do coll)

; good
coll

lint/when-do

EnabledAdded
true0.1

when already defines an implicit do. Rely on it.

Examples

; bad
(when x (do (println :a) (println :b) :c))

; good
(when x (println :a) (println :b) :c)

lint/when-not-call

EnabledAdded
true0.1

when-not exists so use it lol.

Examples

; bad
(when (not x) :a :b :c)

; good
(when-not x :a :b :c)

lint/when-not-do

EnabledAdded
true0.1

when-not already defines an implicit do. Rely on it.

Examples

; bad
(when-not x (do (println :a) (println :b) :c))

; good
(when-not x (println :a) (println :b) :c)

lint/when-not-empty?

EnabledAdded
true0.1

seq returns nil when given an empty collection. empty? is implemented as (not (seq coll)) so it's best and fastest to use seq directly.

Examples

; bad
(when-not (empty? ?x) &&. ?y)

; good
(when (seq ?x) &&. ?y)

lint/when-not-not

EnabledAdded
true0.1

Two nots cancel each other out.

Examples

; bad
(when-not (not x) y z)

; good
(when x y z)

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close