Skip to content

noReturnInFinally (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noReturnInFinally": "error"
}
}
}
}

Disallow return statements in Promise.prototype.finally() callbacks.

Returning a value from a Promise.prototype.finally() callback is ignored, which can be confusing. Returned promises and thenables are awaited, and their rejection rejects the resulting promise.

Returns inside nested blocks, including conditional branches and loops, are also disallowed. Returns inside nested functions are ignored by the rule.

Promise.resolve(1).finally(() => { return 2 });
code-block.js:1:36 lint/nursery/noReturnInFinally ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Returning a value from a finally callback is not allowed.

> 1 │ Promise.resolve(1).finally(() => { return 2 });
^^^^^^^^
2 │

The return value in a finally callback is ignored, making any return statement potentially confusing.

Remove the return statement from the finally callback to resolve this issue.

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.

myPromise.finally(() => { return 2 });
code-block.js:1:27 lint/nursery/noReturnInFinally ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Returning a value from a finally callback is not allowed.

> 1 │ myPromise.finally(() => { return 2 });
^^^^^^^^
2 │

The return value in a finally callback is ignored, making any return statement potentially confusing.

Remove the return statement from the finally callback to resolve this issue.

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.

myPromise.finally(() => {
if (condition) {
return 2;
}
});
code-block.js:3:9 lint/nursery/noReturnInFinally ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Returning a value from a finally callback is not allowed.

1 │ myPromise.finally(() => {
2 │ if (condition) {
> 3 │ return 2;
^^^^^^^^^
4 │ }
5 │ });

The return value in a finally callback is ignored, making any return statement potentially confusing.

Remove the return statement from the finally callback to resolve this issue.

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.

Promise.resolve(1).finally(() => { console.log(2) });
myPromise.finally(() => {});
myPromise.finally(function () {
function nested() {
return 2;
}
console.log(nested());
});