Skip to content

[no-unsafe-enum-comparison] consider evaluating switch statements #7509

Closed
@mrazauskas

Description

@mrazauskas

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.2.1-rc&fileType=.ts&code=KYOwrgtgBAasDmwAuBDARgG2FA3gKCigEEBnABxQCcV4wSoBeKAchXKpruYBoCoAhSgHsAxiKEYAloxZphYiZJ54AvnjwATYCIxVsWJFABuCZOiwAuWKdSZgAbnWSAZlAAUJxLayMGTVuzUtCTMAJS4fAD0kVAaQlAkQhDIABaSIPCqTq4eNubYfv5youJSYRGE0bHxiclIaRlZeCQA7pJIIinunmZ24fiEImzYARRBXBZ8lTFxCUmp6ZmEhHLAKADWjnxDJCPFCmWTy1BVs7ULjcerG45qQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tieQEMAZonpNYAW1pkOY4nyrIOTdFETRoHaJHBgAviB1A&tsconfig=&tokens=false

Repro Code

enum Vegetable {
  Asparagus = 'asparagus',
  Broccoli = 'broccoli',
}

declare let vegetable: Vegetable;

if (vegetable === 'asparagus') {
  // do something
}

if (vegetable === 'broccoli') {
  // do something
}

switch (vegetable) {
  case 'asparagus':
    // do something
    break;

  case 'broccoli':
    // do something
    break;
}

ESLint Config

module.exports = {
  "rules": {
    "@typescript-eslint/no-unsafe-enum-comparison": "error"
  }
}

tsconfig

{
  "compilerOptions": {
    // ...
  }
}

Expected Result

I would expect ESLint to error on comparisons in the switch statement, because those comparisons look similar to the ones in the if...else statements.

Actual Result

ESLint reports errors only for comparisons of the if...else statements.

Additional Info

Might be I missed something. Could not find anything similar in the issues, so opening this one for discussion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions