Credence.Pattern.NoCaseTrueFalse
(credence v0.4.4)
Copy Markdown
Detects case expr do true -> …; false -> … end that should be if/else.
LLMs frequently transliterate Python's if/else through a case on a
boolean expression with explicit true/false (or _) clauses. Idiomatic
Elixir uses if/else when the condition is already a boolean.
Only flags cases where the subject is a boolean expression (comparison, function call, operator) — not a plain variable, which may be a legitimate pattern match on a tristate value.
Detected patterns
case expr do true -> A; false -> B end
case expr do false -> B; true -> A end
case expr do true -> A; _ -> B end
case expr do false -> B; _ -> A endBad
case rem(n, 2) == 0 do
true -> :even
false -> :odd
endGood
if rem(n, 2) == 0 do
:even
else
:odd
endAuto-fix
Rewrites the case to if/else, placing the true body (or the wildcard
counterpart) in the do block and the false body in else.