Thanks to visit codestin.com
Credit goes to github.com

Skip to content

New erl_files (-hrl +beam) rule: {elvis_style, guard_operators} #462

@paulo-ferraz-oliveira

Description

@paulo-ferraz-oliveira

Name

consistent_guard_operators

Brief Description

Avoid using a mix of andalso, orelse, ,, and ;, by choosing a consistent coding style for guard expressions.

Problematic code

foo(X) when is_integer(X), X > 0 orelse is_float(X) ->

Correct code

foo(X) when is_integer(X), X > 0; is_float(X) ->

Rationale

Both andalso/orelse, or ,/; provide some intent and short-circuit semantics. Mixing the two, though, can lead to subtle bugs or reduce readability, especially for newcomers.

Choose one style appropriate for the expression and stick to it within a guard to improve code clarity and maintainability.

Option

preferred_syntax => [punctuation | words]

  • punctuation is [;, ,] (the default)
  • words is [orelse, andalso] (we're not considering and or or since we already have a rule specific to that)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions