Credence.Semantic.UnusedVariable
(credence v0.7.1)
Copy Markdown
Fixes compiler warnings about unused variables by adding _ prefix.
LLMs often generate destructuring patterns where not all bound variables
are used, causing --warnings-as-errors to fail compilation.
Example
# Warning: variable "current_sum" is unused
{current_sum, max_sum} = Enum.reduce(...)
# Fixed:
{_current_sum, max_sum} = Enum.reduce(...)How the fix locates the binding
The compiler diagnostic carries a {line, col} position pointing at
the first character of the unused binding (1-indexed). The fix
uses that column strictly:
- if
var_namelives at that exact column with non-word characters on both sides, insert_there; - otherwise refuse to act — silently mangling the wrong identifier is far worse than leaving the warning visible.
When the diagnostic carries only a line (no column), the fix falls
back to "rewrite only if var_name appears exactly once on the line
as a standalone identifier" — same safety principle.