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
Add no-duplicate-case documentation note about ignoring side effects #15552
Comments
Hi @Dionysusnu, thanks for the issue! I can reproduce this with the default parser as well: online demo. This is indeed not a duplicate, but I think it's a good case for |
While trying that, I noticed that it seemed impossible to do that in a single comment, because of the other rule switch (1) {
case x++:
case x++: {
break;
}
} Adding in the eslint-disable comment above the second case, the no-fallthrough rule would start to trigger, probably because it disallows anything but consecutive lines. I didn't find a way to disable both rules in a single comment. |
Have you considered linking this demo in the issue format? I tried looking for something like it but couldn't find it. |
The spirit of the rule is to highlight potential copy-paste errors, which this looks like it could be, so I think the current behavior is the expected behavior and disable comments are the right way to deal with exceptions. |
@Dionysusnu good idea! #15557 takes a stab at that. I agree with the rest of the team that side effects feel out of scope for this rule to handle. |
Can you use /* eslint no-duplicate-case: error */
/* eslint no-fallthrough: error */
switch (1) {
case x++:
case x++: { // eslint-disable-line no-duplicate-case
break;
}
} |
That works! I thought I'd tried that already, but I guess not properly. Thanks for the help. |
I marked this as an accepted issue to update the docs, and prepared PR #15563 |
Environment
Node version: v16.13.1
npm version: 7.13.0
Local ESLint version: v8.7.0
Global ESLint version: N/A
Operating System: Windows 10 Home
What parser are you using?
@typescript-eslint/parser
What did you do?
Configuration
What did you expect to happen?
Since the code has side effects, the cases being checked are not identical/duplicate, so no error should be generated.
What actually happened?
The code generated a false-positive error on cases that are not duplicate.
Participation
Additional comments
I realise this is a very niche case, I found this while enabling eslint on unit tests for a compiler, hence the code testing special edge case behaviours.
The text was updated successfully, but these errors were encountered: