Skip to content
This repository was archived by the owner on Jan 8, 2026. It is now read-only.

Latest commit

 

History

History
231 lines (186 loc) · 11.7 KB

File metadata and controls

231 lines (186 loc) · 11.7 KB

Elixir Linter Rules

Below is a list of rules we use for our credo.exs.
this is adapted from credo here

Consistency.ExceptionNames

  • Exception names should have a common prefix or suffix, a common choice is have all of them end in Error read more

Consistency.LineEndings

  • Use line-endings consistently (Unix-style line endings are preferred) read more

Consistency.SpaceAroundOperators

  • Use spaces around operators and after commas read more

Consistency.SpaceInParentheses

  • Don't use spaces after (, [, and { or before }, ], and ) read more

Consistency.TabsOrSpaces

Design.TagTODO

  • Use TODO: comments to plan changes to your code read more

Design.TagFIXME

  • Use FIXME: comments to plan changes to your code read more

Readability.FunctionNames

  • Function and macro names are always written in snake_case in Elixir read more

Readability.LargeNumbers

  • Numbers can contain underscores for readability purposes read more

Readability.MaxLineLength

  • Checks for the length of lines. (max 80) read more

Readability.ModuleAttributeNames

  • Module attribute names are always written in snake_case in Elixir read more

Readability.ModuleDoc

  • Every module should contain comprehensive documentation read more

Readability.ModuleNames

  • Module names are always written in PascalCase in Elixir read more

Readability.ParenthesesInCondition

  • Because if and unless are macros, the preferred style is to not use parentheses around conditions. read more

Readability.PredicateFunctionNames

  • Predicate functions/macros should return a boolean value, for functions, they should end in a question mark.
# preferred way
def valid?(username) do
  # ...
end

# NOT okay
def is_valid?(username) do
  # ...
end

read more

Readability.TrailingBlankLine

  • Files should end in a trailing blank line read more

Readability.TrailingWhiteSpace

  • There should be no white-space (i.e. tabs, spaces) at the end of a line read more

Readability.VariableNames

  • Variable names are always written in snake_case in Elixir read more

Refactor.ABCSize

  • The ABC size describes a metric based on assignments, branches and conditions.
  • A high ABC size is a hint that a function might be doing "more" than it should. read more

Refactor.CondStatements

  • Each cond statement should have 3 or more statements including the "always true" statement. read more

Refactor.FunctionArity

  • A function can take as many parameters as needed, but even in a functional language there can be too many parameters. read more

Refactor.MatchInCondition

  • Pattern matching should only ever be used for simple assignments inside if and unless clauses. read more

Refactor.PipeChainStart

  • Pipes (|>) can become more readable by starting with a "raw" value. read more

Refactor.CyclomaticComplexity

  • Cyclomatic complexity is a software complexity metric closely correlated with coding errors
  • If a function feels like it's gotten too complex, it more often than not also has a high CC value read more

Refactor.NegatedConditionsInUnless

  • Unless blocks should not contain a negated condition read more

Refactor.NegatedConditionsWithElse

  • An if block with a negated condition should not contain an else block read more

Refactor.Nesting

  • Code should not be nested more than once inside a function read more

Refactor.UnlessWithElse

  • An unless block should not contain an else block read more

Warning.IExPry

  • Most calls to the IExPry function are added during debugging sessions
  • This check warns about those calls, because they might have been committed in error read more

Warning.IoInspect

  • Most calls to the IoInspect function are added during debugging sessions
  • This check warns about those calls, because they might have been committed in error read more

Warning.NameRedeclarationByAssignment

  • The names of local variables should not be the same as names of functions or macros in the same module or in Kernel. read more

Warning.NameRedeclarationByCase

  • Names assigned to choices in a case statement should not be the same as names of functions in the same module or in Kernel. read more

Warning.NameRedeclarationByDef

  • Names assigned to parameters of a named function should not be the same as names of functions in the same module or in Kernel. read more

Warning.NameRedeclarationByFn

  • Names assigned to parameters of an anonymous function should not be the same as names of functions in the same module or in Kernel read more

Warning.OperationOnSameValues

Warning.BoolOperationOnSameValues

  • Boolean operations with identical values on the left and right side are most probably a logical fallacy. read more

Warning.UnusedEnumOperation

  • With the exception of Enum.each/2, the result of a call to the Enum module's functions has to be used. read more

Warning.UnusedKeywordOperation

  • The result of a call to the Keyword module's functions has to be used. read more

Warning.UnusedListOperation

  • The result of a call to the List module's functions has to be used. read more

Warning.UnusedStringOperation

  • The result of a call to the String module's functions has to be used. read more

Warning.UnusedTupleOperation

  • The result of a call to the Tuple module's functions has to be used. read more

Warning.OperationWithConstantResult

  • Operations on the same values always yield the same result and therefore make little sense in production code. read more