Allow `commentPattern: null` in no-fallthrough
See original GitHub issueWhat rule do you want to change?
no-fallthrough
Does this change cause the rule to produce more or fewer warnings?
more
How will the change be implemented? (New option, new default behavior, etc.)?
The existing option "commentPattern"
will allow null
value.
This will be the official way to disable the commentPattern
feature of this rule for users who prefer explicit eslint-disable
comments or maybe want to completely disallow falling through case clauses.
A current workaround is to set a pattern that can never match.
Please provide some example code that this change will affect:
/* eslint no-fallthrough: "error" */
switch (foo) {
case 1:
bar();
// eslint-disable-next-line no-fallthrough
case 2:
baz();
}
What does the rule currently do for this code?
When run with --report-unused-disable-directives
, ESLint reports:
7:3 error Unused eslint-disable directive (no problems were reported from 'no-fallthrough')
This is because the comment happens to be both an eslint-disable directive and a directive for the no-fallthrough
rule (since the comment matches the default commentPattern
) at the same time, so no-fallthrough
actually doesn’t report an error.
What will the rule do after it’s changed?
If "commentPattern": null
is set, no comments will match.
I think that this option ideally shouldn’t have a default value, but that might be a big breaking change.
Are you willing to submit a pull request to implement this change?
Yes.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:6 (6 by maintainers)
Top GitHub Comments
Oops misinterpreted the earlier comment. Even without a breaking change, I’d still prefer not changing the current behavior and just documenting the problem. It seems like the issue is more one of people not understanding how to use the rule rather than a problem with the rule itself.
I realized that the purpose of this rule is actually to mark intentional fall-throughs, not to disallow fall-throughs, so this proposal doesn’t make sense.