Skip to content

Bug: [switch-exhaustiveness-check] Some cases for member names are not being fixed properly #7768

Closed
@StyleShit

Description

@StyleShit

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=4.9.3&showAST=es&fileType=.tsx&code=KYOwrgtgBAglDeAoKUBCUC8UCMAaZUA5AMIC0ATIZlOfigNoAGAIqQMyMC61bdUTAUVKIRKACxdqY-AF8RAE2ABjADYBDAE7AoSgPYgAzgBcoagFywRBgO4BLI0oAWUABRqAlAgJK1B7TAA6VAt4KCNHDV1rKBBgaIENSI0XQgA5XRNbCAAHFWAIUCNgeSgAT2AjC0D0Hz9CTzkZIA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6ZAd0vzIAt6AHrwCGsZPkoA3RExTJafRGQDW6KImjQA9tEjgwAXxAGgA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Run the fixer and you'll notice the issue

Repro Code

enum A {
  B = 1,
  'C-2' = 2,
  [`D-3`] = 3,
  [`E-


  4`] = 4,
}

declare const a: A

switch (a) {
  case A.B: { throw new Error('Not implemented yet: A.B case') }
}

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/switch-exhaustiveness-check": ["error"],
  },
};

tsconfig

No response

Expected Result

Probably this?

switch (a) {
  case A.B: { throw new Error('Not implemented yet: A.B case') }
  case A['C-2']: { throw new Error('Not implemented yet: A[\'C-2\'] case') }
  case A['D-3']: { throw new Error('Not implemented yet: A[\'D-3\'] case') }
  case A[`E-


  4`]: { throw new Error('Not implemented yet: A[`E-


  4`] case') }
}

Actual Result

switch (a) {
  case A.B: { throw new Error('Not implemented yet: A.B case') }
  case A['C-2']: { throw new Error('Not implemented yet: A['C-2'] case') }
  case A['D-3']: { throw new Error('Not implemented yet: A['D-3'] case') }
  case A['E-


  4']: { throw new Error('Not implemented yet: A['E-


  4'] case') }
}

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: 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