Liking cljdoc? Tell your friends :D

Style

style/new-object

EnabledAdded
true0.1

new is discouraged for dot usage.

Examples:

; bad
(new java.util.ArrayList 100)

; good
(java.util.ArrayList. 100)

style/prefer-boolean

EnabledAdded
true0.1

Use boolean if you must return true or false from an expression.

Examples:

# bad
(if some-val true false)
(if (some-func) true false)

# good
(boolean some-val)
(boolean (some-func))

Reference

style/prefer-clj-math

EnabledAdded
true0.1

Prefer clojure.math to interop.

Examples:

# bad
Math/PI
(Math/atan 45)

# good
clojure.math/PI
(clojure.math/atan 45)

style/prefer-condp

EnabledAdded
true0.1

cond checking against the same value in every branch is a code smell.

This rule uses the first test-expr as the template to compare against each other test-expr. It has a number of conditions it checks as it runs:

  • The cond is well-formed (aka even number of args).
  • The cond has more than 1 pair.
  • The first test-expr is a list with 3 forms.
  • The function of every test-expr must match the test-expr of the first test-expr.
    • The last test-expr isn't checked if it is true or a keyword.
  • The last argument of every test-expr must match the last argument of the first test-expr.

Provided all of that is true, then the middle arguments of the test-exprs are gathered and rendered into a condp.

Examples:

# bad
(cond
  (= 1 x) :one
  (= 2 x) :two
  (= 3 x) :three
  (= 4 x) :four)

# good
(condp = x
  1 :one
  2 :two
  3 :three
  4 :four)

# bad
(cond
  (= 1 x) :one
  (= 2 x) :two
  (= 3 x) :three
  :else :big)

# good
(condp = x
  1 :one
  2 :two
  3 :three
  :big)

Reference

style/prefer-vary-meta

EnabledAdded
true0.1

vary-meta works like swap!, so no need to access and overwrite in two steps.

Examples:

; bad
(with-meta x (assoc (meta x) :filename filename))

; good
(vary-meta x assoc :filename filename)

style/redundant-let

EnabledAdded
true0.1

Directly nested lets can be merged into a single let block.

Examples:

# bad
(let [a 1]
  (let [b 2]
    (println a b)))

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

style/single-key-in

EnabledAdded
true0.1

assoc-in loops over the args, calling assoc for each key. If given a single key, just call assoc directly instead for performance and readability improvements.

Examples:

; bad
(assoc-in coll [:k] 10)

; good
(assoc coll :k 10)

Can you improve this documentation?Edit on GitHub

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

× close