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:
cond
is well-formed (aka even number of args).cond
has more than 1 pair.true
or a keyword.Provided all of that is true, then the middle arguments of the test-exprs are
gathered and rendered into a condp
.
Examples:
(cond (= 1 x) :one (= 2 x) :two (= 3 x) :three (= 4 x) :four)
(condp = x 1 :one 2 :two 3 :three 4 :four)
(cond (= 1 x) :one (= 2 x) :two (= 3 x) :three :else :big)
(condp = x 1 :one 2 :two 3 :three :big)
`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)
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close