Skip to content
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

Rule "no-fallthrough" falsely triggers when using curly brackets #9559

Closed
danielhickman opened this issue Nov 1, 2017 · 1 comment
Closed
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules

Comments

@danielhickman
Copy link

What version are you using?
v4.9.0

What did you do?

Config:

{
    "env": {
        "es6": true,
        "node": true
    },
    "extends": "eslint:recommended",
    "parserOptions": {
        "sourceType": "module"
    },
    "rules": {
        "no-fallthrough": [
            "error",
            {
                "commentPattern": "falls?\\s?through|break"
            }
        ]
    }
}

Code:

const item = "Test string";
switch (typeof item) {
	case "string": {
		// Run as if it was a number (below)
		// fallthrough
	}
	case "number": {
		console.log(item);
		break;
	}
}

What happened?

Console (worked as intended):

Test string

ESLint:

Expected a 'break' statement before 'case'. (no-fallthrough)

What did you expect to happen?

The same as without curly brackets, right? Removing the first or all of the case brackets prevents ESLint from erroring out the no-fallthrough message.

Code:

const item = "Test string";
switch (typeof item) {
	case "string":
		// Run as if it was a number (below)
		// fallthrough
	case "number": 
		console.log(item);
		break;
}

The empty block looks good for consistency especially since I want to comment something and not "stack" the case statements on top of each other.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Nov 1, 2017
@aladdin-add aladdin-add added bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Nov 1, 2017
@nzakas
Copy link
Member

nzakas commented Oct 24, 2018

Unfortunately, it looks like there wasn't enough interest from the team or community to implement this change. While we wish we'd be able to accommodate everyone's requests, we do need to prioritize. We've found that issues failing to be implemented after 90 days tend to never be implemented, and as such, we close those issues. This doesn't mean the idea isn't interesting or useful, just that it's not something the team can commit to.

@nzakas nzakas closed this as completed Oct 24, 2018
evelynhathaway added a commit to evelynhathaway/eslint that referenced this issue Oct 25, 2018
The rule `no-fallthrough` now gets the `SwitchCase` that falls through passed into the function where the comment is found and checked. In that function, if the falllthrough case has a block, it looks for a matching comment inside the block.

Also added are corresponding tests and an example in the documentation for the switch case block.
evelynhathaway added a commit to evelynhathaway/eslint that referenced this issue Oct 25, 2018
The rule `no-fallthrough` now gets the `SwitchCase` that falls through passed into the function where the comment is found and checked. In that function, if the falllthrough case has a block, it looks for a matching comment inside the block.

Also added are corresponding tests and an example in the documentation for the switch case block.
Rev
evelynhathaway added a commit to evelynhathaway/eslint that referenced this issue Oct 25, 2018
The rule `no-fallthrough` now gets the `fallthroughCase` passed into the function `hasFallthroughComment`. In that function, it looks for the comment directly before the falllthrough case's block in addition to directly before the current case.

Also added are corresponding tests and an example in the documentation for the switch case block.
evelynhathaway added a commit to evelynhathaway/eslint that referenced this issue Oct 25, 2018
The rule `no-fallthrough` now gets the `fallthroughCase` passed into the function `hasFallthroughComment`. In that function, it looks for the comment directly before the fallthrough case's block in addition to directly before the current case.

Also added are corresponding tests and an example in the documentation for the switch case block.
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Apr 23, 2019
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Apr 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants