question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: no-useless-else rule

See original GitHub issue

Please 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:closed
  • Created 7 years ago
  • Reactions:9
  • Comments:20 (17 by maintainers)

github_iconTop GitHub Comments

11reactions
not-an-aardvarkcommented, Feb 5, 2017

👍 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 and continue).

Maybe we could rename it to no-useless-else or something.

1reaction
btmillscommented, Jan 19, 2018

@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 use no-useless-else?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found