Skip to main content

no-equal-then-else

has auto-fix
free+

Warns when an if statement has equal then and else statements or conditional expression has equal then and else expressions.

Example

❌ Bad:

final firstValue = 1;
final secondValue = 2;

...

// LINT: This expression has equal 'then' and 'else' branches.
if (condition) {
result = firstValue;
} else {
result = firstValue;
}

...

// LINT: This expression has equal 'then' and 'else' branches.
result = condition ? firstValue : firstValue;

✅ Good:

final firstValue = 1;
final secondValue = 2;

...

if (condition) {
result = firstValue;
} else {
result = secondValue; // Correct, different value
}

...

result = condition ? firstValue : secondValue;

Additional Resources