Skip to main content

no-equal-conditions

added in: 1.1.0
Pro+
preset: recommended

Warns when a if statement has duplicate conditions.

Duplicate conditions are usually a sign of a bug (another condition should be used instead) or just dead code that can be simply removed.

Example

❌ Bad:

void main() {
final value = 1;

if (value == 1) {
return value;
} else if (value == 2) {
return value;
// LINT: Avoid duplicate conditions in 'if/else if'. Try replacing the duplicate condition or removing it.
} 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;
}
}

Additional Resources