Skip to content

[no-type-alias] eslint crashes when a type alias contains parentheses #575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yokuze opened this issue May 29, 2019 · 0 comments · Fixed by #576
Closed

[no-type-alias] eslint crashes when a type alias contains parentheses #575

yokuze opened this issue May 29, 2019 · 0 comments · Fixed by #576
Labels
bug Something isn't working has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@yokuze
Copy link

yokuze commented May 29, 2019

The no-type-alias rule code crashes eslint with a stack trace when a type alias contains parentheses.

Repro

{
   "plugins": [
      "@typescript-eslint"
   ],

   "overrides": [
      {
         "files": [ "*.ts" ],
         "parser": "@typescript-eslint/parser",
         "rules": {
            "@typescript-eslint/no-type-alias": "error"
         }
      }
   ]
}
type A = number & (string | boolean);

Note: removing the parentheses from the statement above does not produce a stack trace.

Expected Result
No stack trace. The no-type-alias rule should report linting violations.

Actual Result
A stack trace, and eslint does not output any violations.

Additional Info

  eslint:cli CLI args: [ 'index.ts', '-c', 'eslintrc.json', '--debug' ] +0ms
  eslint:cli Running on files +5ms
  eslint:config Using command line config eslintrc.json +0ms
  eslint:config-file Loading JSON config file: /redacted/eslint-ts-bug/eslintrc.json +0ms
  eslint:plugins Loaded plugin @typescript-eslint (@typescript-eslint/eslint-plugin@1.9.0) (from /redacted/eslint-ts-bug/node_modules/@typescript-eslint/eslint-plugin/dist/index.js) +0ms
  eslint:glob-utils Creating list of files to process. +0ms
  eslint:ignored-paths baseDir = "/redacted/eslint-ts-bug" +0ms
  eslint:ignored-paths addPatternRelativeToCwd:
  eslint:ignored-paths   original = "/node_modules/*"
  eslint:ignored-paths   cooked   = "/node_modules/*" +1ms
  eslint:ignored-paths addPatternRelativeToCwd:
  eslint:ignored-paths   original = "/bower_components/*"
  eslint:ignored-paths   cooked   = "/bower_components/*" +0ms
  eslint:ignored-paths addPatternRelativeToCwd:
  eslint:ignored-paths   original = ".*"
  eslint:ignored-paths   cooked   = ".*" +0ms
  eslint:ignored-paths addPatternRelativeToCwd:
  eslint:ignored-paths   original = "!../"
  eslint:ignored-paths   cooked   = "!../" +1ms
  eslint:ignored-paths Looking for ignore file in /redacted/eslint-ts-bug +0ms
  eslint:ignored-paths Could not find ignore file in cwd +0ms
  eslint:ignored-paths contains: +1ms
  eslint:ignored-paths   target = "/redacted/eslint-ts-bug/index.ts" +0ms
  eslint:ignored-paths   result = false +0ms
  eslint:ignored-paths contains: +0ms
  eslint:ignored-paths   target = "/redacted/eslint-ts-bug/index.ts" +0ms
  eslint:ignored-paths   result = false +0ms
  eslint:cli-engine Processing /redacted/eslint-ts-bug/index.ts +0ms
  eslint:cli-engine Linting /redacted/eslint-ts-bug/index.ts +0ms
  eslint:config Constructing config file hierarchy for /redacted/eslint-ts-bug +308ms
  eslint:config Using .eslintrc and package.json files +0ms
  eslint:config Loading /redacted/eslint-ts-bug/package.json +1ms
  eslint:config-file Loading package.json config file: /redacted/eslint-ts-bug/package.json +308ms
  eslint:config-file Loading JSON config file: /redacted/eslint-ts-bug/package.json +0ms
  eslint:config Loading /redacted/package.json +0ms
  eslint:config-file Loading package.json config file: /redacted/package.json +0ms
  eslint:config-file Loading JSON config file: /redacted/package.json +1ms
  eslint:config Using command line config file +1ms
  eslint:config-ops Using config from partial cache +0ms
  eslint:config-ops Apply environment settings to config +0ms
  eslint:linter Linting code for /redacted/eslint-ts-bug/index.ts (pass 1) +0ms
  eslint:traverser Unknown node type "TSTypeAliasDeclaration": Estimated visitor keys ["type","id","typeAnnotation","range","loc"] +0ms
  eslint:traverser Unknown node type "TSIntersectionType": Estimated visitor keys ["type","types","range","loc"] +0ms
  eslint:traverser Unknown node type "TSNumberKeyword": Estimated visitor keys ["type","range","loc"] +0ms
  eslint:traverser Unknown node type "TSParenthesizedType": Estimated visitor keys ["type","typeAnnotation","range","loc"] +0ms
  eslint:traverser Unknown node type "TSUnionType": Estimated visitor keys ["type","types","range","loc"] +0ms
  eslint:traverser Unknown node type "TSStringKeyword": Estimated visitor keys ["type","range","loc"] +0ms
  eslint:traverser Unknown node type "TSBooleanKeyword": Estimated visitor keys ["type","range","loc"] +0ms
  eslint:linter An error occurred while traversing +34ms
  eslint:linter Filename: /redacted/eslint-ts-bug/index.ts +0ms
  eslint:linter Line: 1 +0ms
  eslint:linter Parser Options: { ecmaVersion: undefined } +0ms
  eslint:linter Parser Path: @typescript-eslint/parser +0ms
  eslint:linter Settings: {} +0ms
TypeError: Cannot read property '0' of undefined
Occurred while linting /redacted/eslint-ts-bug/index.ts:1
    at Object.upperCaseFirst (/redacted/eslint-ts-bug/node_modules/@typescript-eslint/eslint-plugin/dist/util/misc.js:25:15)
    at getMessage (/redacted/eslint-ts-bug/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-type-alias.js:167:36)
    at validateTypeAliases (/redacted/eslint-ts-bug/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-type-alias.js:203:32)
    at node.types.forEach.type (/redacted/eslint-ts-bug/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-type-alias.js:215:21)
    at Array.forEach (<anonymous>)
    at validateCompositions (/redacted/eslint-ts-bug/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-type-alias.js:210:24)
    at TSTypeAliasDeclaration (/redacted/eslint-ts-bug/node_modules/@typescript-eslint/eslint-plugin/dist/rules/no-type-alias.js:222:21)
    at listeners.(anonymous function).forEach.listener (/redacted/eslint-ts-bug/node_modules/eslint/lib/util/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/redacted/eslint-ts-bug/node_modules/eslint/lib/util/safe-emitter.js:45:38)

Versions

package version
@typescript-eslint/eslint-plugin 1.9.0
@typescript-eslint/parser 1.9.0
TypeScript 3.4.5
ESLint 5.16.0
node 8.10.0
npm 6.4.1
@yokuze yokuze added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels May 29, 2019
@bradzacher bradzacher added bug Something isn't working has pr there is a PR raised to close this and removed triage Waiting for team members to take a look labels May 29, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
2 participants