Credence.Rule.NoUnderscoreFunctionName
(credence v0.3.2)
Copy Markdown
Detects function names that use a leading underscore to indicate privacy, a convention borrowed from Python that is non-idiomatic in Elixir.
Why this matters
In Python, _private_method signals "internal use." In Elixir, defp
is the privacy mechanism, and a leading underscore on a name signals
"unused variable" — not "private function." LLMs frequently generate
helper functions like _factorial, _do_find, or _fibonacci because
their training data mixes Python and Elixir conventions.
The Elixir convention for recursive helpers is the do_ prefix:
# Flagged — Python convention
defp _factorial(0, acc), do: acc
defp _factorial(n, acc), do: _factorial(n - 1, n * acc)
# Idiomatic — Elixir convention
defp do_factorial(0, acc), do: acc
defp do_factorial(n, acc), do: do_factorial(n - 1, n * acc)Detection scope
Flags any def or defp clause where the function name starts with
a single underscore. Names starting with double underscores __)
are excluded — those are legitimate Elixir/Erlang callbacks such as
__using__/1, __before_compile__/1, and __info__/1.
Auto-fix
Renames the function definition and all call sites from _name to
do_name throughout the module.