Credence.Pattern.NoRedundantUnderscoreBind (credence v0.8.0)

Copy Markdown

Detects _ = var bindings in pattern position (function heads, case/fn clause heads, with/for generators) and simplifies them to just var.

In pattern position _ = var matches anything and binds it to var, which is identical to just var — the underscore adds no value.

Bad

def foo(_ = x), do: x + 1

Good

def foo(x), do: x + 1

Not flagged — statement position

A standalone _ = var in a block body is NOT redundant: it is the idiom Elixir's own warning recommends to consume a bound-but-unused value without the "variable has no effect / is never returned" warning (NimbleParsec- and macro-generated code rely on it). Rewriting it to a bare var statement reintroduces exactly that warning, so we only fire in pattern position.