ForgeCredoChecks.InconsistentParamNames (forge_credo_checks v0.7.0)

Copy Markdown View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of high and works with any version of Elixir.

Explanation

Parameter names should match across clauses of the same function.

Why

LLMs write function clauses semi-independently and let the parameter names drift between them:

# Flagged -- position 1 is `current` in one clause, `prev` in another
defp do_fib(current, _next, 0), do: current
defp do_fib(prev, current, steps), do: do_fib(current, prev + current, steps - 1)

# Consistent
defp do_fib(prev, _current, 0), do: prev
defp do_fib(prev, current, steps), do: do_fib(current, prev + current, steps - 1)

Drift makes readers question correctness: if position 1 is current in one clause and prev in another, which is the real intent?

Detection

Clauses of the same {name, arity} within the same module are grouped. For each positional argument, base names (with any leading _ stripped) are compared across clauses; differences flag.

Clauses in different defmodule, defimpl, or defprotocol blocks are never compared, even if they share a function name and arity. Protocol implementations idiomatically name parameters after the implementing type, so cross-impl comparison would be a false positive.

Positions where any clause uses a literal, tuple/list pattern, or bare _ are skipped -- destructuring is intentional pattern matching, not a parameter name.

Check-Specific Parameters

There are no specific parameters for this check.

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.