noReturnInFinally (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/noReturnInFinally - This rule doesn’t have a fix.
- The default severity of this rule is information.
- Sources:
- Inspired from
promise/no-return-in-finally
- Inspired from
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noReturnInFinally": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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());});References
Section titled “References”Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.