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.

New rule proposal: no-dupe-else-if

See original GitHub issue

Please describe what the rule should do:

Disallows duplicate test conditions in if-else-if chains.

What category of rule is this? (place an “X” next to just one item)

[X] Warns about a potential error (problem)

Provide 2-3 code examples that this rule will warn about:

if (a > 1) {
    foo();
} else if (a > 1) {
    bar();
}

if (a === 1) {
    foo();
} else if (a === 2) {
    bar();
} else if (a === 3) { 
    baz();
} else if (a === 2) {
    quux();
} else if (a === 5) {
    quuux();
}

Why should this rule be included in ESLint (instead of a plugin)?

It’s a possible error. A statement with a duplicate condition can never execute (unless it’s an unusual use case with side effects).

This rule is similar to the existing no-duplicate-case. The error could be due to a copy & paste and a long chain.

The test nodes would be compared by their tokens.

Are you willing to submit a pull request to implement this rule?

Yes.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Oct 28, 2019

I’m working on this 😃

1reaction
mysticateacommented, Oct 28, 2019

Now accepted 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
Enhanced Disclosures by Certain Investment Advisers and ...
Proposed rule. SUMMARY: The Securities and Exchange Commission (“Commission”) is proposing to amend rules and forms under both the Investment ...
Read more >
eslint | Yarn - Package Manager
A new rule is created. A new option to an existing rule that does not result in ESLint reporting more linting errors by...
Read more >
ESLint equivalents in Elm
Comparing ESLint functionality and the equivalents in the Elm ecosystem.
Read more >
disallow reassigning exceptions in catch clauses (no-ex- ...
Rule Details. This rule disallows reassigning exceptions in catch clauses. Examples of incorrect code for this rule: /*eslint no-ex-assign: "error"*/ try ...
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