Credence.Rule.NoRedundantNegatedGuard
(credence v0.2.0)
Copy Markdown
Detects guard clauses that are logically redundant because a preceding clause of the same function already handles the complementary case.
Why this matters
LLMs add "safety" guards because they don't trust Elixir's clause
ordering. When a clause with when a == b precedes one with
when a != b, the second guard is guaranteed to pass — anything
reaching that clause already failed the equality check:
# Flagged — second guard is redundant
defp compare([h1 | t1], [h2 | t2]) when h1 == h2, do: compare(t1, t2)
defp compare([h1 | _], [h2 | _]) when h1 != h2, do: h1
# Idiomatic — clause ordering handles it
defp compare([h1 | t1], [h1 | t2]), do: compare(t1, t2)
defp compare([missing | _], _), do: missingFlagged patterns
A function clause whose guard is when a != b or when a !== b,
immediately preceded by a clause of the same function/arity with
when a == b or when a === b (same variables, same positions).
Severity
:info