Credence.Pattern.NoRedundantAssignment
(credence v0.8.0)
Copy Markdown
Detects a single plain variable being assigned and immediately returned as the last two statements of a block.
This is a common verbosity pattern where the assignment adds no value. In Elixir, the last expression in a block is its return value, so the intermediate binding is unnecessary.
Example
# Bad
result = compute(x)
result
# Good
compute(x)Only a single plain variable is fixed. Tuple/list patterns ({a, b} = process(input); {a, b}) are left alone: collapsing them would discard the
match's implicit arity assertion, so the rewrite would not be strictly
behavior-preserving.
Auto-fix
Replaces the last two statements with just the RHS of the assignment.