bradzacher/eslint-plugin-typescript

[no-unused-vars] Crash when running ESLint

ficristo opened this issue · 8 comments

Repro

{
  "rules": {
    "no-unused-vars": [1, {"vars": "all", "args": "none"}],
    "typescript/no-unused-vars": "warn"
  }
}

I cannot hunt down the code where it breaks

Expected Result
ESLint should pass.

Actual Result

Warning: Cannot read property 'type' of undefined Use --force to continue.
TypeError: Cannot read property 'type' of undefined
    at isForInRef (F:\github\quadre\node_modules\eslint\lib\rules\no-unused-vars.js:406:24)
    at variable.references.some.ref (F:\github\quadre\node_modules\eslint\lib\rules\no-unused-vars.js:443:21)
    at Array.some (<anonymous>)
    at isUsedVariable (F:\github\quadre\node_modules\eslint\lib\rules\no-unused-vars.js:442:40)
    at collectUnusedVariables (F:\github\quadre\node_modules\eslint\lib\rules\no-unused-vars.js:565:26)
    at collectUnusedVariables (F:\github\quadre\node_modules\eslint\lib\rules\no-unused-vars.js:572:17)
    at collectUnusedVariables (F:\github\quadre\node_modules\eslint\lib\rules\no-unused-vars.js:572:17)
    at Program:exit (F:\github\quadre\node_modules\eslint\lib\rules\no-unused-vars.js:617:36)
    at listeners.(anonymous function).forEach.listener (F:\github\quadre\node_modules\eslint\lib\util\safe-emitter.js:47:58)
    at Array.forEach (<anonymous>)

Additional Info
At the moment I cannot update ESLint to version 5.*
See also eslint/typescript-eslint-parser#553

See quadre-code/quadre#103 where I upgraded typescript-eslint-parser, when I got this error.
Trying to use this plugin didn't fix the crash.
To see the error on my project I run grunt eslint --stack --debug.

Versions

package version
eslint-plugin-typescript 0.13.0
typescript-eslint-parser 21.0.1
typescript 3.1.6
eslint 4.19.1
j-f1 commented

Does my suggestion in #170 help here?

I would hazard a guess that this is a bug introduced by typescript-eslint-parser@21.

@ficristo please try downgrading your version of typescript-eslint-parser to ^15.
If that fixes the problem, then sweet!

there have been a number of breaking changes to the parser. there are some contributors working on testing it against the newer versions.

My previous version was 15.0.0 and ESLint worked. For now I just disabled the rule on ts and tsx code, so to be able to upgrade the parser.

@ficristo do you mind trying to run eslint from console with --debug flag?
it should print you additional data to locate line

like:

eslint --ext .tsx,.ts --debug src/

https://eslint.org/docs/user-guide/command-line-interface#--debug

--debug
This option outputs debugging information to the console. This information is useful when you’re seeing a problem and having a hard time pinpointing it. The ESLint team may ask for this debugging information to help solve bugs.

Running this
node_modules/.bin/eslint --ext .tsx,.ts --ignore-path .gitignore --debug . &> result.txt

Here the result.txt

@ficristo i managed to reproduce this

        enum Foo {
            BAR = 'bar',
            BAZ = 'baz'
        }
        export default Foo

looks like its due to parser not plugin :>

i updated ticket there

@j-f1 issue got solved and merged in eslint/typescript-eslint-parser#556

Fixed upstream.