New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New rule proposal: no-dupe-else-if #12469
New rule proposal: no-dupe-else-if #12469
Comments
One more 👍 to accept this. |
Now accepted 🎉 |
I'm working on this :-) |
just a thought: for consecutive if(foo === 0) {...}
if(foo === 0) {...} // to warn, or not? I think it's good to cover it, or behide an option as an enhancement. |
I think it's more suitable for a separate rule because this isn't necessarily an error (it could be just a bad practice to repeat conditions instead of having all code in a single block, or it might be even a correct code if |
Agreed with @mdjermanovic. I don't think this rule should catch this, since this rule shouldn't be disallowing code like the following: function checkForB(a) { return a.b; }
function checkForC(a) { return a.c; }
const d = {
c: true
};
let e = checkForB(d);
if (e !== undefined) {/* Do something */}
e = checkForC(d);
if (e !== undefined) {/* Do something */} or even if we limit it to consecutive statements, potentially: function checkForB(a) { return a.b; }
function checkForC(a) { return a.c; }
const d = {
b: true
};
let e = checkForB(d);
if (e !== undefined) {
if (typeof e !== 'number') {
e = checkForC(d);
}
}
if (e !== undefined) {/* Do something */} |
emm.. after thinking for a while, I think it's not fit for this rule:
|
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:
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.
The text was updated successfully, but these errors were encountered: