inaka / elvis_core

The core of an Erlang linter
Other
61 stars 56 forks source link

New rule: No Single Clause Maybe Statements #293

Open paulo-ferraz-oliveira opened 1 year ago

paulo-ferraz-oliveira commented 1 year ago

No Single Clause Maybe Statements

Brief Description

The following code...

maybe
    {ok, A} ?= a()
end

... should actually be written using pattern-matching:

{ok, A} = a()

The maybe statement is unnecessary and the only difference between the two is that the exception raised in the case of error changes from else_clause to badmatch.

If an else_clause is present, though, the rule should not be applied.

Should be on by default?

YES

Options

Reasoning

Single-pattern maybe blocks may be written more concisely or removed entirely.

Origin

Inspired by #290.