Skip to main content

avoid-contradictory-expressions

added in: 1.14.0

Warns when several conditions contradict each other.

Example

❌ Bad:

void fn() {
final num = 1;
final anotherNum = 2;

if (anotherNum == 3 && anotherNum == 4) {} // LINT
if (anotherNum < 4 && anotherNum > 4) {} // LINT
if (anotherNum == 2 && anotherNum != 2) {} // LINT
if (anotherNum == num && anotherNum != num) {} // LINT
}

✅ Good:

void fn() {
final num = 1;
final anotherNum = 2;

if (anotherNum == 3 || anotherNum == 4) {}
if (anotherNum < 4 && anotherNum > 2) {}
if (anotherNum == 2) {}
if (anotherNum == num) {}
}