OptimumCredo.Check.Refactor.AdjacentClauseOneLiteral (OptimumCredo v0.5.0)
View SourceBasics
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
Adjacent clauses that differ only in one literal value can often become one clause with a parameter. Reported when the only differences are a single literal pair; small clauses are skipped. Readable separate clauses are a valid choice. Opt-in, low priority.
Bad
def sort(:name), do: Repo.all(from(u in User, where: u.active, order_by: field(u, :name)))
def sort(:email), do: Repo.all(from(u in User, where: u.active, order_by: field(u, :email)))The two clauses differ only in :name / :email, so one clause with a parameter
(def sort(key)) is enough.
Check-Specific Parameters
Use the following parameters to configure this check:
:min_nodes
Smallest clause size, in AST call nodes, that is reported.
This parameter defaults to 6.
General Parameters
Like with all checks, general params can be applied.
Parameters can be configured via the .credo.exs config file.