Aller au contenu

noUselessReturn

Ce contenu n’est pas encore disponible dans votre langue.

biome.json
{
"linter": {
"rules": {
"nursery": {
"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/nursery/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.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

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/nursery/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.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

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/nursery/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.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

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;
}
}