Skip to content

noUselessReturn

biome.json
{
"linter": {
"rules": {
"complexity": {
"noUselessReturn": "error"
}
}
}
}

Disallow redundant return statements.

A return; statement with nothing after it is redundant when it is the last reachable statement in a function body. Removing it does not change the function’s behavior, as execution naturally falls through to the end.

function foo() {
return;
}
code-block.js:2:5 lint/complexity/noUselessReturn  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This return statement is unnecessary.

1 │ function foo() {
> 2 │ return;
^^^^^^^
3 │ }
4 │

Removing this statement does not change the control flow of the function.

Safe fix: Remove the unnecessary return statement.

1 1 function foo() {
2 - ····return;
3 2 }
4 3

function foo() {
doSomething();
return;
}
code-block.js:3:5 lint/complexity/noUselessReturn  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This return statement is unnecessary.

1 │ function foo() {
2 │ doSomething();
> 3 │ return;
^^^^^^^
4 │ }
5 │

Removing this statement does not change the control flow of the function.

Safe fix: Remove the unnecessary return statement.

1 1 function foo() {
2 2 doSomething();
3 - ····return;
4 3 }
5 4

function foo() {
if (condition) {
bar();
return;
}
}
code-block.js:4:9 lint/complexity/noUselessReturn  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This return statement is unnecessary.

2 │ if (condition) {
3 │ bar();
> 4 │ return;
^^^^^^^
5 │ }
6 │ }

Removing this statement does not change the control flow of the function.

Safe fix: Remove the unnecessary return statement.

2 2 if (condition) {
3 3 bar();
4 - ········return;
5 4 }
6 5 }

function foo() {
return 5;
}
function foo() {
if (condition) {
return;
}
bar();
}
function foo() {
for (const x of xs) {
return;
}
}