src/content/docs/linter/rules/no-useless-return.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> :::caution This rule is part of the [nursery](/linter/#nursery) group. This means that it is experimental and the behavior can change at any time. ::: ## Summary - Rule available since: `v2.3.15` - Diagnostic Category: [`lint/nursery/noUselessReturn`](/reference/diagnostics#diagnostic-category) - This rule has a [**safe**](/linter/#safe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Inspired from [`no-useless-return`](https://eslint.org/docs/latest/rules/no-useless-return){
"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;
}
function foo() {
doSomething();
return;
}
function foo() {
if (condition) {
bar();
return;
}
}
function foo() {
return 5;
}
function foo() {
if (condition) {
return;
}
bar();
}
function foo() {
for (const x of xs) {
return;
}
}