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.

Conflict between `no-fallthrough` rule and `reportUnusedDisableDirectives` option

See original GitHub issue

Tell 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:closed
  • Created 3 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Sep 6, 2020

"." makes all non-empty comments being the comments that allow fall-through, so I don’t think it helps to avoid conflicts with eslint-disable.

For example, try to run eslint with --report-unused-disable-directives on the following code:

/* eslint no-fallthrough: ["error", { commentPattern: "." }] */

switch (type) {
	case 'foo':
	case 'bar':
		xyz += 'y';

	// eslint-disable-next-line no-fallthrough
	case 'baz':
		xyz += 'z';
		break;

	default:
}
  8:2  error  Unused eslint-disable directive (no problems were reported from 'no-fallthrough')

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 and false 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: "[]" }.

1reaction
anikethsahacommented, Aug 28, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

no-fallthrough - ESLint - Pluggable JavaScript Linter
This rule is aimed at eliminating unintentional fallthrough of one case to the other. As such, it flags any fallthrough scenarios that are...
Read more >
How do I safely fix ESLint`no-fallthrough` error for intentional ...
I understand that there are ways to design this differently, i.e. with if statements and early return pattern, which is my usual approach....
Read more >
eslint-config-eslint | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
The Difference Between Node.js 10 LTS and Node.js 12 LTS
The JSON variant of the API documentation is no longer ... The default value of the windowsHide option has been changed to true...
Read more >
parseroptions.project has been set for @typescript-eslint/parser
DO NOT SET createDefaultProgram to true to prevent future breakage. ... Different lint rules for JavaScript and TypeScript files.
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