Proposal: no-useless-else rule
See original GitHub issuePlease describe what the rule should do:
If an if
block contains a throw
statement, the else
block becomes unnecessary. Its contents can be placed outside of the block.
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:
// With this rule, this would cause ESLint to warn:
if (foo)
throw new Error('foo');
else
return bar;
// This rule would *not* warn about this:
if (foo)
throw new Error('foo');
return bar;
Why should this rule be included in ESLint (instead of a plugin)?
It seems generally applicable. It is analogous to the currently-include no-else-return
rule.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:9
- Comments:20 (17 by maintainers)
Top Results From Across the Web
How a Proposal Becomes a Rule - California Courts - CA.gov
For proposals that will be effective January 1, this process typically takes approximately one year. Submission of a Proposal. Many of the changes...
Read more >SEC Proposed Rules
SEC Proposed Rules · Regulation NMS: Minimum Pricing Increments, Access Fees, and Transparency of Better Priced Orders · File No: S7-30-22 · Comments...
Read more >10 Rules for Writing a Winning Proposal - CBS News
RULE #6. Nobody is interested in the history of your firm or your product. Make the proposal about how you'll solve the customer's...
Read more >sindresorhus/eslint-plugin-unicorn (Raised $2856.00)
Rule proposal: Error when adding a class that begins with a dot`classList.add('.` Unfunded#1837created byuniversemaster. $0.00.
Read more >5 Rules for Writing a Project Proposal - iThemes
Need to write a project proposal? In this post, we cover five rules for writing a project proposal, plus how to qualify clients...
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
👍 for having a way to report this, but I wonder if it would be better to just expand the
no-else-return
rule to include all statements that cause control flow jumps (return
,throw
,break
andcontinue
).Maybe we could rename it to
no-useless-else
or something.@platinumazure I added one more 👍 so we can accept this, and yes, going with @not-an-aardvark’s
no-useless-else
proposal. @Trott would you be willing to update your original issue to useno-useless-else
?