Credo.Check.Refactor.UnlessWithElse (Credo v1.5.0-rc.5) 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!"
end

This should be refactored:

unless allowed? do
  raise "Not allowed!"
else
  proceed_as_planned()
end

to look like this:

if allowed? do
  proceed_as_planned()
else
  raise "Not allowed!"
end

The 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 parameters for this check.

Link to this section Summary

Link to this section Functions

Link to this function

do_run_on_source_file(exec, source_file, params)

View Source