Rbtz.CredoChecks.Readability.SnakeCaseVariableNumbering (rbtz_credo_checks v0.3.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 normal and works with any version of Elixir.

Explanation

Encourages numbered variables to use a separating underscore: user_1, user_2 rather than user1, user2.

The underscore makes it visually obvious that the trailing digit is an index, not part of the name. It also matches the rest of the snake_case convention used in Elixir code.

Bad

user1 = %{name: "alice"}
user2 = %{name: "bob"}

def render(item1, item2), do: ...

Good

user_1 = %{name: "alice"}
user_2 = %{name: "bob"}

def render(item_1, item_2), do: ...

The check looks at every variable reference in the file. Each violating name is reported once at its first occurrence.

Names where any snake_case component matches an entry in :exclude are skipped. Matching is component-wise, not substring — with exclude: ["md5"]:

  • md5, md5_hash, file_md5, content_md5_digest are ignored

  • md5sum1 is still flagged (md5 is not a whole component there)

    {Rbtz.CredoChecks.Readability.SnakeCaseVariableNumbering, [exclude: ["md5", "sha1", "sha256"]]}

Check-Specific Parameters

Use the following parameters to configure this check:

:exclude

List of snake_case components (strings or atoms) to ignore. A variable is skipped when any of its underscore-separated components matches an entry.

This parameter defaults to [].

General Parameters

Like with all checks, general params can be applied.

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