Credence.Pattern.NoGuardEqualityForPatternMatch
(credence v0.7.0)
Copy Markdown
Readability rule: Detects guard clauses that compare a parameter to a
literal value with == when pattern matching in the function head would
be clearer and more idiomatic.
This only flags simple var == literal comparisons where var is one of
the function's parameters and literal is an atom or string. Number
literals are deliberately excluded: when n == 0 matches 0.0 (value equality)
but the head f(0) does not (pattern uses ===), so substituting a number
would change which clause a float-equal value routes to.
Bad
defp do_count(n, _a, b) when n == 2, do: b
def process(action) when action == :stop, do: :haltedGood
defp do_count(2, _a, b), do: b
def process(:stop), do: :halted