Rule request: no-useless-return
See original GitHub issuePlease describe what the rule should do:
Forbid return;
at the end of a function, as it is redundant. It’s often a leftover from refactoring some callback code.
What category of rule is this? (place an “X” next to just one item)
[x] Enforces code style [ ] Warns about a potential error [ ] Suggests an alternate way of doing something [ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
The common case:
function foo() {
bar();
return; // pointless!
}
Generalising to conditionals at the end of a function:
function foo() {
if (something) {
bar();
return; // redundant
} else if (otherThing) {
baz();
return; // redundant
} else {
boz();
}
// Nothing here, so the arms of the conditional are the last thing
// in the function.
}
Examples where we wouldn’t warn:
function foo() {
bar();
return 1;
}
Why should this rule be included in ESLint (instead of a plugin)?
It’s totally generic and applicable to all JS developers I think.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:14 (14 by maintainers)
Top Results From Across the Web
no-useless-return - ESLint - Pluggable JavaScript Linter
A return; statement with nothing after it is redundant, and has no effect on the runtime behavior of a function. This can be...
Read more >Disallow redundant return statements (no-useless-return)
A return; statement with nothing after it is redundant, and has no effect on the runtime behavior of a function. This can be...
Read more >no-useless-return - Rules - ESLint - Pluggable JavaScript linter
A return; statement with nothing after it is redundant, and has no effect on the runtime behavior of a function.
Read more >Disallow redundant return statements (no-useless-return) #694
A return statement with nothing after it is redundant, and has no effect on the runtime behavior of a function. This can be...
Read more >No-useless-return - ESLint - W3cubDocs
A return; statement with nothing after it is redundant, and has no effect on the runtime behavior of a function. This can be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I also can implement this since I like code path analysis. 😄
Sounds great! I’ll endorse this. With two more endorsements and a champion, we can accept this.