Green. Lexmag. ElixirStyleGuideFormatter
(green v0.2.0)
Copy Markdown
Usage
Add the following to your mix.exs:
defp deps do
[
{:green, "~> VERSION"}
]
endCheck the latest version of Green on Hex.pm.
Modify .formatter.exs to activate the formatter plugin:
[
plugins: [Green.Lexmag.ElixirStyleGuideFormatter]
]Status of rules
The implemented rules are marked with a check ✅.
When it is possible to transform the code to match the style guide, Green will do so.
When automatic transformation is not possible, Green will
leave the code as it is and print a warning. These are marked with an
exclamation mark ❗.
Rules that are not implemented are marked with a question mark ❔. This
includes rules where there is no way to objectively judge them, such as
usefulness of comments.
Rules that are implemented by the compiler or mix format are marked with
a thumbs up 👍.
Linting
✅ Transform nested function calls into pipelines (Source, Configuration).
✅ Transform one-element pipelines into function calls (Source),
❔ Don't use anonymous functions in pipelines (Source),
✅ Transform unless...else... into if...else... (Source),
✅ Transform if...else nil into if... (Source),
✅ Ensure match-all condition of cond has true (Source),
❔ Use and and or instead of && and || when the arguments are boolean (Source),
✅ Use <> instead of bitstrings when pattern-matching binaries (Source).
Naming
❗ Enforce snake_case for atoms, functions, variables, attributes (Source, Configuration),
👍 Enforce CamelCase for modules (Source),
❔ Enforce predicate functions to end with a question mark (Source),
✅ Enforce snake_case for directories and files (Source),
❗ Disallow one-letter variable names (Source).
Comments
❔ Use only critical comments (Source),
❔ Avoid superfluous comments (Source).
Modules
✅ Group and order use, import, alias and require statements (Source),
Notes:
- This transformation does not take into account comments. Any comment before
or on the same line as a
use,import,aliasorrequirestatement will be left where it is.
✅ Replace the current module name with __MODULE__ (Source).
Regular Expressions
❔ Prefer pattern matching over regular expressions (Source),
❔ Use non-capturing regular expressions (Source).
Structs
✅ Don't specify nil default values for defstruct fields (Source).
Exceptions
❗ Use Error suffix for exception names (Source),
❔ Use non-capitalized error messages (except for Mix error messages) without trailing punctuation (Source).
ExUnit
❔ Put the expression being tested by comparison on the left side (Source).
Parentheses
✅ Parentheses are a must for local or imported zero-arity function calls (Source, Configuration).