Skip to main content

avoid-self-compare

added in: 1.1.0
preset: recommended

Warns when a comparison has both sides exactly the same.

Example

❌ Bad:

void main() {
final val = '1';

// LINT
if (val == val) {
return;
}

// LINT
if (val.length == val.length) {
return;
}

// LINT
if (val > val) {
return;
}

// LINT
if (val < val) {
return;
}
}

✅ Good:

void main() {
final val = '1';
final anotherVal = '2';

if (val == anotherVal) {
return;
}

if (val.length == anotherVal.length) {
return;
}

if (val > anotherVal) {
return;
}

if (val < anotherVal) {
return;
}
}