Credence.Pattern.NoUnlessElse (credence v0.4.5)

Copy Markdown

Detects unless ... do ... else ... end — a style guide violation.

The Elixir style guide says: "Never use unless with else. Rewrite these with the positive case first."

The fix swaps unless to if and reverses the branch bodies. The condition is never modified.

Bad

unless MapSet.member?(set, value) do
  :missing
else
  :found
end

Good

if MapSet.member?(set, value) do
  :found
else
  :missing
end

Auto-fix

Replaces unless with if and swaps the do/else bodies.