Skip to main content

no-equal-conditions

added in: 1.1.0
preset: recommended

Warns when a if statement has duplicate conditions.

Duplicating a condition automatically leads to dead code. Usually, this is due to a copy/paste error. At best, it's simply dead code and at worst, it's a bug that is likely to induce further bugs as the code is maintained, and obviously it could lead to unexpected behavior.

Example

❌ Bad:

void main() {
final value = 1;

if (value == 1) {
return value;
} else if (value == 2) {
return value;
// LINT
} else if (value == 1) {
return value;
}
}

✅ Good:

void main() {
final value = 1;

if (value == 1) {
return value;
} else if (value == 2) {
return value;
} else if (value == 3) {
return value;
}
}