Rbtz. CredoChecks. Readability. ModuleAttrCollectionFormatting
(rbtz_credo_checks v0.6.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 multi-line collections assigned to module attributes to list one item per line, so the collection stays easy to scan, diff, and update.
Once a list / word sigil / map / tuple assigned to a @module_attribute
is broken across multiple lines, cramming several items onto one line
makes it hard to see what changed in a diff and easy to mis-edit. Putting
each item on its own line keeps every addition or removal to a single
line.
Only module-attribute values are inspected, and only when the collection already spans more than one line. A single-line collection is always fine, no matter how many items it holds.
Covered forms: word sigils (~w[...] / ~W[...]), list literals
([...], including keyword lists), maps and structs (%{...} /
%Mod{...}), and tuples ({...}). Interpolated ~w sigils are not
inspected.
Bad — multi-line with more than one item on a line
@allowed_extensions ~w[
.png .jpg .jpeg
.gif .webp
]
@supported_locales [
"en-US", "en-GB",
"fr-FR", "de-DE"
]
@retry_backoff {
1_000, 2_000,
5_000
}Good — one item per line
@allowed_extensions ~w[
.png
.jpg
.jpeg
.gif
.webp
]
@supported_locales [
"en-US",
"en-GB",
"fr-FR",
"de-DE"
]Good — a single line is fine, however many items
@allowed_extensions ~w[.png .jpg .jpeg .gif .webp]
@supported_locales ["en-US", "en-GB", "fr-FR", "de-DE"]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.