Credence.Pattern.NoUnusedUnderscoreAssignment
(credence v0.8.0)
Copy Markdown
Removes a dead _var = <pure> binding left behind by the unused-variable fix.
When the semantic UnusedVariable rule prefixes an unused variable with _,
it leaves a dead assignment such as _length = list whose value is never
read. A human deterministically deletes that line.
Example
# Bad
def process(list) do
_length = list
n = length(list)
if n < 3, do: 0, else: n
end
# Good
def process(list) do
n = length(list)
if n < 3, do: 0, else: n
endSafe core (narrowed)
An assignment is removed only when all hold, so the deletion can never change behaviour:
- the left side is a single underscore-prefixed variable (
_name), not a destructuring pattern; - the right side is a trivially pure expression — a literal (number, atom, string, boolean, nil) or a bare variable — so removing it skips no side effect and can raise nothing;
- the variable name occurs exactly once in the whole input (this binding and nowhere else), so nothing reads it;
- the assignment is not the last expression of its block (the last expression is the block's value).
Anything outside that core (a call/operator RHS, a referenced variable, a destructuring left side, a last-position binding) is left untouched.