Skip to content

Bug: no-fallthrough interaction with disable comments and "unused disable directive" warnings #16650

@bradzacher

Description

@bradzacher

Environment

ESLint version: 8.29.0

What parser are you using?

Default (Espree)

What did you do?

Configuration
module.exports = {
  reportUnusedDisableDirectives: true,
  rules: {
    'no-fallthrough': 'error',
  },
};
switch (test) {
  case a:
    hello();

  // eslint-disable-next-line no-fallthrough
  case b:
}

What did you expect to happen?

The rule report should be hidden and no "unused disable directive" warnings should be reported.

What actually happened?

An unused disable directive warning is reported
image

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

This default behaviour is problematic because if you run eslint --fix, then eslint will remove the unused disable comment, causing no-fallthrough error.

I think that this occurs because the default comment regex will match the no-fallthrough string

const DEFAULT_FALLTHROUGH_COMMENT = /falls?\s?through/iu;

IMO either the rule should ignore eslint-disable directives, or the default regex should be updated to ignore them to prevent this behaviour.

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionbugESLint is working incorrectlyrepro:yesIssues with a reproducible example

    Type

    No type

    Projects

    Status

    Complete

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions