typescript-eslint icon indicating copy to clipboard operation
typescript-eslint copied to clipboard

Bug: Program body element type exception

Open loynoir opened this issue 10 months ago • 2 comments

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

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

Relevant Package

ast-spec

Playground Link

No response

Repro Code

// `rule.test.ts` input code
function a() { return 42 }; export {a}

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/<rule-name>": ["error", ...<options>],
  },
};

tsconfig

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

Expected Result

Remove // @ts-expect-error: workaround for wrong type

Actual Result

rule.ts

        Program(node): void {
          node.body.forEach((el) => {
            switch (el.type) {
              // @ts-expect-error: workaround for wrong type
              case AST_NODE_TYPES.EmptyStatement:
                console.error('BUG: types error means code will not reached, but code actaully reached')
                break
            }
          })

run rule.test.ts

BUG: types error means code will not reached, but code actaully reached

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin ^7.6.0
@typescript-eslint/parser ^7.6.0
@typescript-eslint/rule-tester ^7.6.0
@typescript-eslint/scope-manager ^7.6.0
@typescript-eslint/typescript-estree ^7.6.0
@typescript-eslint/type-utils ^7.6.0
@typescript-eslint/utils ^7.6.0
TypeScript ^5.4.4
ESLint ^8.57.0
node v21.7.1

loynoir avatar Apr 09 '24 11:04 loynoir

Yea, looks like EmptyStatement is missing in Statement union

https://github.com/typescript-eslint/typescript-eslint/blob/074310029694f92323d4d91f0fd31df39698d0e7/packages/ast-spec/src/unions/Statement.ts#L34C13-L34C22

But EmptyStatement is part of Statement according to ECMAScript - https://262.ecma-international.org/14.0/#prod-Statement

playground link

auvred avatar Apr 09 '24 12:04 auvred

@auvred based on your comment, should this be "accepting prs"?

kirkwaiblinger avatar May 07 '24 03:05 kirkwaiblinger