Skip to content

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

@danielhickman

Description

@danielhickman

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    archived due to ageThis issue has been archived; please open a new issue for any further discussionbugESLint is working incorrectlyevaluatingThe team will evaluate this issue to decide whether it meets the criteria for inclusionruleRelates to ESLint's core rules

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions