avoid-excessive-expressions
preset: recommended
Warns when a condition has excessive expressions.
Excessive expressions do not affect the result of the condition and can be simply removed.
Example
❌ Bad:
void fn() {
final num = 1;
final anotherNum = 2;
// LINT: This expression is redundant. Try updating this expression or replacing it with a different expression.
if (anotherNum == 3 && anotherNum != 4) {}
// LINT: This non-null check is redundant since the next expression implicitly checks for a non-null value. Try removing this expression or replacing it with a different expression.
if (num != null && num is int) {}
// LINT: This null check is redundant since the next expression implicitly checks for a null value. Try removing this expression or replacing it with a different expression.
if (num == null || num is! int) {}
// LINT: This expression is redundant. Try updating this expression or replacing it with a different expression.
if (5 < anotherNum && anotherNum > 4) {}
}
✅ Good:
void fn() {
final num = 1;
final anotherNum = 2;
if (anotherNum != 3 && anotherNum != 4) {} // Correct, different condition
if (num is int) {}
if (num is! int) {}
if (2 < anotherNum && anotherNum < 4) {}
}