OptimumCredo.Check.Readability.AssignOrder (OptimumCredo v0.5.0)

View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

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

Explanation

Keep chained assigns in alphabetical order, with pinned keys such as :module first.

Bad

socket
|> assign(:title, "Hi")
|> assign(:module, __MODULE__)
|> assign(:count, 0)

Good

socket
|> assign(:module, __MODULE__)
|> assign(:count, 0)
|> assign(:title, "Hi")

Chains shorter than min_run keys are ignored.

Check-Specific Parameters

Use the following parameters to configure this check:

:min_run

Minimum number of keys in a chain.

This parameter defaults to 3.

:pinned_assigns

Keys that must stay first.

This parameter defaults to [:module].

General Parameters

Like with all checks, general params can be applied.

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