Credence.Pattern.NoIdentityFloatCoercion
(credence v0.4.4)
Copy Markdown
Detects identity arithmetic used to coerce an integer to a float.
LLMs carry Python idioms (x * 1.0, x / 1.0, x + 0.0) into Elixir,
where they are unnecessary. If a float result is needed, Elixir's /
operator always returns a float naturally.
Detected patterns
expr * 1.0 1.0 * expr
expr / 1.0
expr + 0.0 0.0 + expr
expr - 0.0Note: 0.0 - expr is NOT flagged — it negates, not coerces.
Bad
Enum.at(sorted_list, mid) * 1.0
Enum.at(combined, mid_index) / 1.0
count = count + 0.0Good
Enum.at(sorted_list, mid)
Enum.at(combined, mid_index)
# (self-assignment line removed entirely)Auto-fix
Removes the identity operand and operator from the expression. When the
entire line is a no-op self-assignment (var = var * 1.0), the line is
deleted.