Skip to main content

avoid-redundant-else

added in: 1.1.0
🛠
preset: recommended

Checks for else blocks that can be removed without changing semantics.

Example

❌ Bad:

class SomeClass {
String someString = '123';

void withInstance() {
if (someString == '0') {
print("Nothing to do");
return;
} else { // LINT
print("Moving on...");
}
}
}

✅ Good:

class SomeClass {
String someString = '123';

void withInstance() {
if (someString == '0') {
print("Nothing to do");
return;
}

print("Moving on...");
}
}