OptimumCredo.Check.Refactor.ConditionalOnParameter (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

Prefer several function clauses or guards over a single body that is just a case or if on one of the parameters. Opt-in, low priority; only single-expression bodies are inspected.

Bad

def label(kind) do
  case kind do
    :admin -> "Admin"
    :member -> "Member"
  end
end

Good

def label(:admin), do: "Admin"
def label(:member), do: "Member"

Check-Specific Parameters

Use the following parameters to configure this check:

:min_case_clauses

Minimum number of case clauses to report.

This parameter defaults to 2.

:check_if

Also report if/unless that test a parameter.

This parameter defaults to true.

General Parameters

Like with all checks, general params can be applied.

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