Skip to main content

avoid-equal-expressions

has auto-fix
pro+

Warns when both sides of a binary expression are the same.

Example

❌ Bad:

// LINT: Avoid duplicate expressions.
// Try removing the duplicate expression or replacing it with a different expression.
if (_isOneShifting() && _isOneShifting()) {
return;
}

// LINT: Avoid duplicate expressions.
// Try removing the duplicate expression or replacing it with a different expression.
if (num == anotherNum && num == anotherNum) {
return;
}

// LINT: Avoid duplicate expressions.
// Try removing the duplicate expression or replacing it with a different expression.
if (num == anotherNum || num == anotherNum) {
return;
}

// LINT: Avoid duplicate expressions.
// Try removing the duplicate expression or replacing it with a different expression.
final val = num << num;

// LINT: Avoid duplicate expressions.
// Try removing the duplicate expression or replacing it with a different expression.
final val = num >> num;

// LINT: Avoid duplicate expressions.
// Try removing the duplicate expression or replacing it with a different expression.
final val = 5 / 5;

// LINT: Avoid duplicate expressions.
// Try removing the duplicate expression or replacing it with a different expression.
final val = 10 - 10;

✅ Good:

if (_isOneShifting() && _anotherOne()) { // Correct, different invocation
return;
}

if (num == anotherNum) {
return;
}

if (num == anotherNum) {
return;
}

final val = num << anotherNum;
final val = num >> anotherNum;

Additional Resources