Skip to main content

avoid-unnecessary-return

added in: 1.6.0
🛠
Pro+
preset: recommended

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

Example

❌ Bad:

const _value = 1;

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

return; // LINT: Unnecessary return statement. Try removing it.
} else {
...
}
}

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

return; // LINT: Unnecessary return statement. Try removing it.
}
}

void anotherOne() {
...

return; // LINT: Unnecessary return statement. Try removing it.
}

✅ Good:

const _value = 1;

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

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

void anotherOne() {
...
}