Credo.Check.Refactor.UnlessWithElse (Credo v1.5.2) View Source
This check has a base priority of high and works with any version of Elixir.
Explanation
An unless block should not contain an else block.
So while this is fine:
unless allowed? do
raise "Not allowed!"
endThis should be refactored:
unless allowed? do
raise "Not allowed!"
else
proceed_as_planned()
endto look like this:
if allowed? do
proceed_as_planned()
else
raise "Not allowed!"
endThe reason for this is not a technical but a human one. The else in this
case will be executed when the condition is met, which is the opposite of
what the wording seems to apply.
Configuration parameters
There are no specific parameters for this check.
Like with all checks, general params can be applied.
Parameters can be configured via the .credo.exs config file.