Skip to main content

avoid-unnecessary-return

added in: 1.6.0
🛠

Warns when a return statement is unnecessary and can be removed.

Example

❌ Bad:

const _value = 1;

void someFunction() {
if (_value == 2) {
...

return; // LINT
} else {
...
}
}

void another() {
if (_value == 2) {
...

return; // LINT
}
}

void anotherOne() {
...

return; // LINT
}

✅ Good:

const _value = 1;

void someFunction() {
if (_value == 2) {
...
} else {
...
}
}

void another() {
if (_value == 2) {
...
}
}

void anotherOne() {
...
}