Skip to content

no-unused-vars triggers an error on declare enum #396

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
mgol opened this issue Apr 1, 2019 · 2 comments · Fixed by #418
Closed

no-unused-vars triggers an error on declare enum #396

mgol opened this issue Apr 1, 2019 · 2 comments · Fixed by #418
Labels
documentation Documentation ("docs") that needs adding/updating package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@mgol
Copy link
Contributor

mgol commented Apr 1, 2019

What code were you trying to parse?

declare enum Test {
  Foo,
}

What did you expect to happen?

It should lint the code & not crash.

What actually happened?

With the following configuration:

"rules": [
  "no-unused-vars": [
    "error",
    {
      "args": "all",
      "argsIgnorePattern": "^_",
      "ignoreRestSiblings": true
    }
  ]
]

trying to lint the file with source provided above crashes with an error:

TypeError: Cannot read property 'parent' of undefined
Occurred while linting test.d.ts:1
    at variable.defs.some.def (project/node_modules/eslint/lib/rules/no-unused-vars.js:184:54)
    at Array.some (<anonymous>)
    at hasRestSpreadSibling (project/node_modules/eslint/lib/rules/no-unused-vars.js:182:38)
    at collectUnusedVariables (project/node_modules/eslint/lib/rules/no-unused-vars.js:578:80)
    at collectUnusedVariables (project/node_modules/eslint/lib/rules/no-unused-vars.js:585:17)
    at Program:exit (project/node_modules/eslint/lib/rules/no-unused-vars.js:630:36)
    at listeners.(anonymous function).forEach.listener (project/node_modules/eslint/lib/util/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (project/node_modules/eslint/lib/util/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (project/node_modules/eslint/lib/util/node-event-generator.js:251:26)

Versions

package version
@typescript-eslint/eslint-plugin 1.5.0
@typescript-eslint/parser 1.5.0
TypeScript 3.3.4000
ESLint 5.15.3
node v8.15.1
npm N/A
yarn 1.15.2
@mgol mgol added package: parser Issues related to @typescript-eslint/parser triage Waiting for team members to take a look labels Apr 1, 2019
@bradzacher
Copy link
Member

Could you try again with @typescript-eslint/no-unused-vars instead?
The base eslint rule no-unused-vars does not support typescript code.

@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Apr 7, 2019
@mgol
Copy link
Contributor Author

mgol commented Apr 7, 2019

Thanks, it works with @typescript-eslint/no-unused-vars.

I was confused by ROADMAP.md which references no-unused-vars first and only in a footnote mentions @typescript-eslint/no-unused-vars as "adding support for some TS-specific features". It suggests the original rule should still at least not crash. Given this issue, should the doc be changed to just reference @typescript-eslint/no-unused-vars instead?

bradzacher added a commit that referenced this issue Apr 9, 2019
The roadmap shouldn't recommend the base no-unused-vars rule up front in the table as it doesn't work with typescript features.

Fixes #396
@bradzacher bradzacher added documentation Documentation ("docs") that needs adding/updating package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin and removed awaiting response Issues waiting for a reply from the OP or another party triage Waiting for team members to take a look package: parser Issues related to @typescript-eslint/parser labels Apr 11, 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
documentation Documentation ("docs") that needs adding/updating package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants