noUselessReturn
Это содержимое пока не доступно на вашем языке.
Summary
Section titled “Summary”- Rule available since:
v2.3.15 - Diagnostic Category:
lint/nursery/noUselessReturn - This rule has a safe fix.
- The default severity of this rule is information.
- Sources:
- Inspired from
no-useless-return
- Inspired from
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noUselessReturn": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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; }}Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.