Conflict between `no-fallthrough` rule and `reportUnusedDisableDirectives` option
See original GitHub issueTell us about your environment
- ESLint Version: 7.7.0
- Node Version: 14.8.0
- npm Version: 6.14.7
What parser (default, @babel/eslint-parser
, @typescript-eslint/parser
, etc.) are you using?
default
Please show your full configuration:
Configuration
module.exports = {
ignorePatterns: [
'node_modules/'
],
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module'
},
env: {
browser: true,
commonjs: true
},
reportUnusedDisableDirectives: true,
rules: {
'no-fallthrough': 'error'
}
};
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
const type = 'bar';
let xyz = 'x';
switch (type) {
case 'foo':
case 'bar':
xyz += 'y';
// eslint-disable-next-line no-fallthrough
case 'baz':
xyz += 'z';
break;
default:
}
console.log(xyz);
eslint .
What did you expect to happen? What actually happened? Please include the actual, raw output from ESLint.
Without // eslint-disable-next-line no-fallthrough
Eslint reports Expected a 'break' statement before 'case'
, which is absolutely correct.
But adding this line, ESLint reports Unused eslint-disable directive (no problems were reported from 'no-fallthrough')
, which is not correct, because this directive suppresses the no-fallthrough
error.
I’ve created a minimal test setup here: https://github.com/jens-duttke/eslint-bug-test
Are you willing to submit a pull request to fix this bug?
No
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (7 by maintainers)
Top GitHub Comments
"."
makes all non-empty comments being the comments that allow fall-through, so I don’t think it helps to avoid conflicts witheslint-disable
.For example, try to run eslint with
--report-unused-disable-directives
on the following code:It’s still the same issue. We just replaced one pattern (the default one) that matches
"eslint-disable-next-line no-fallthrough"
with another pattern that also matches.null
andfalse
currently produce schema validation errors, so we can use one of them as a value that disables the “intentional comment” feature of this rule. That still wouldn’t help to avoid confusion with the default behavior of this rule (changing or removing the default pattern would help, but I’m not sure should we do that even in a major version), but at least provides a clear way to disable this feature. A workaround that can be used at the moment is to set a pattern that cannot match anything, like{ commentPattern: "[]" }
.Thanks for the report.
This is a bug. old discussion https://github.com/eslint/eslint/issues/13260
here is the details: https://github.com/eslint/eslint/issues/13260#issuecomment-624114328