Enhancement of 'no-else-return' rule
See original GitHub issueWhat rule do you want to change? no-else-return
Does this change cause the rule to produce more or fewer warnings? more
How will the change be implemented? (New option, new default behavior, etc.)? adding some options / extension to this rule.
Please provide some example code that this change will affect:
if(something) {
throw new Error();
} else {
return true;
}
---
if(something) {
throw new Error();
}
return true;
if(something) {
return 1;
} else if(sthMore) {
return 2;
}
---
if(something) {
return 1;
}
if(sthMore) {
return 2;
}
if(something) {
return 1;
} else {
throw new Error();
}
---
if(something) {
return 1;
}
throw new Error();
What does the rule currently do for this code?
it does sometimes work for the last case. it doesn’t change if else
statements.
What will the rule do after it’s changed?
adds support for Errors
- they ‘work quite similar to returns’
adds support for if else
Are you willing to submit a pull request to implement this change? unfortunatelly don’t have time. Could help with some information
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Rule Change: no-else-return should catch break / continue ...
What will the rule do after it's changed? should propose to remove unnecessary else because: break statement terminates the current loop ...
Read more >javascript - Unnecessary 'else' after 'return'. (No-else-return)
What that is basically saying is that the else part of the if statement is unnecessary if there is a return in the...
Read more >no-else-return - Pluggable JavaScript Linter
This rule is aimed at highlighting an unnecessary block of code following an if containing a return statement. As such, it will warn...
Read more >No Else Return | SamanthaMing.com
I'm going to throw a curve ball and introduce the guard pattern. The guard clause is a block of code that is at...
Read more >tslint-eslint-rules
You want to code in TypeScript but miss all the rules available in ESLint? Now you can combine both worlds by using this...
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
We dont support typescript in core rules. Please use typescript-eslint for config and plugins
because this rule is not about
throw
statements. as per the docsSo even if there is an interest to support
throw
, IMO it has to be in a separate new rule.Unfortunately, it looks like there wasn’t enough interest from the team or community to implement this change. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach accepted status after 21 days tend to never be accepted, and as such, we close those issues. This doesn’t mean the idea isn’t interesting or useful, just that it’s not something the team can commit to.
Thanks for contributing to ESLint and we appreciate your understanding.