Skip to content

noUselessReturn (JavaScript)

Language JavaScript (and super languages)
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;
}
}

Removing a trailing return; can make TypeScript report error TS7030 (“Not all code paths return a value”). This happens when the same function returns a value on another path and the noImplicitReturns compiler option is enabled. In the following example, the rule reports the return;, but removing it breaks the type check when that option is enabled:

function foo(flag: boolean) {
if (flag) {
return 1;
}
return;
}
code-block.ts:5:5 lint/complexity/noUselessReturn  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This return statement is unnecessary.

3 │ return 1;
4 │ }
> 5 │ return;
│ ^^^^^^^
6 │ }
7 │

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

ℹ Safe fix: Remove the unnecessary return statement.

3 3 │ return 1;
4 4 │ }
5 │ - ····return;
6 5 │ }
7 6 │

The same applies to JavaScript files that are checked with checkJs. Biome doesn’t read the noImplicitReturns option from tsconfig.json, so the rule can’t tell whether it is enabled.

If the return; is intentional, you can suppress this specific diagnostic with an inline suppression:

function foo(flag: boolean) {
if (flag) {
return 1;
}
// biome-ignore lint/complexity/noUselessReturn: required by noImplicitReturns
return;
}

Alternatively, you can disable this rule’s fix by setting its fix option to "none". This disables the fix for every return; reported by the rule, not only those affected by noImplicitReturns.