-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
A-lintArea: New lintsArea: New lints
Description
What it does
Suggests replacing if-else expressions where one branch is a boolean literal with &&
/ ||
operators.
Advantage
- Boolean expressions are easier to read and understand and are more concise.
Drawbacks
- There could be cases where the underlying reasoning is made more obvious by the explicit if-else.
- The control flow is clearer.
&&
and||
obscure branching.
Example
if a {
b
} else {
false
}
→ a && b
if a {
true
} else {
b
}
→ a || b
The other two combinations are less clear wins: I'd generally prefer !a || b
to if a {b} else {true}
, but exceptions seem more likely here. Of course, something like if !a {b} else {true}
is much better as a || b
.
Metadata
Metadata
Assignees
Labels
A-lintArea: New lintsArea: New lints