Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

no-unused-variable rule crashes on ES6 bare imports #451

Closed
felixbillon opened this issue Jun 22, 2015 · 12 comments
Closed

no-unused-variable rule crashes on ES6 bare imports #451

felixbillon opened this issue Jun 22, 2015 · 12 comments

Comments

@felixbillon
Copy link

Hie everyone,

I'm using tslint with grunt-tslint and i got an issue when i run it, since I moved on ES6 external module. I got this message :

Fatal error: Cannot read property 'name' of undefined

Can I get some extra output with special parameter ?
Anyoby have an idea ?

Tslint worked well when i was using internal module with 'module' keyword.

@adidahiya
Copy link
Contributor

which version of tslint are you using?

@felixbillon
Copy link
Author

I'm using 2.2.0-beta, then i tried with 2.3.0-beta but I got same result.

@adidahiya
Copy link
Contributor

Can you post the full error output? That looks similar to an error that was fixed in 2.3.0-beta when adding support for TS 1.5 syntax.

@felixbillon
Copy link
Author

@adidahiya of course, this is the output :

errortslint

@adidahiya
Copy link
Contributor

What is the minimal amount of TS code for which this error occurs? I need some more help to reproduce this bug.

@felixbillon
Copy link
Author

I find the problem, this code cause that error :

import 'jquery';
import 'signalR';
import 'angular';
//...

This file is name libs.ts and I use it with browserify to bundle all my vendor libs in one package.

@adidahiya
Copy link
Contributor

Ok, thanks for sharing the code. There must be a bit more info included in the error output... the file where JS is throwing the error should tell you which rule is failing here. Can you try to find that?

@felixbillon
Copy link
Author

This rule crashe "no-unused-variable".

@NickHeiner
Copy link
Contributor

Hey @adidahiya, I think I'm having the same issue @felixbillon is seeing, so I'll just post here instead of opening a new issue.

tslint.json

{
  "rules": {
    "no-unused-variable": true
  }
}

sample.ts

import './app/ng-app.ts'

The command:

λ tslint -f sample.ts 
/Users/nick.heiner/.nvm/v0.11.14/lib/node_modules/tslint/build/rules/noUnusedVariableRule.js:57
            if (importClause.name != null) {
                            ^
TypeError: Cannot read property 'name' of undefined
    at NoUnusedVariablesWalker.visitImportDeclaration (/Users/nick.heiner/.nvm/v0.11.14/lib/node_modules/tslint/build/rules/noUnusedVariableRule.js:57:29)
    at NoUnusedVariablesWalker.SyntaxWalker.visitNode (/Users/nick.heiner/.nvm/v0.11.14/lib/node_modules/tslint/bin/tslint-cli.js:41537:26)
    at /Users/nick.heiner/.nvm/v0.11.14/lib/node_modules/tslint/bin/tslint-cli.js:41639:67
    at visitEachNode (/Users/nick.heiner/.nvm/v0.11.14/lib/node_modules/tslint/bin/tslint-cli.js:5928:30)
    at Object.forEachChild (/Users/nick.heiner/.nvm/v0.11.14/lib/node_modules/tslint/bin/tslint-cli.js:6070:24)
    at NoUnusedVariablesWalker.SyntaxWalker.walkChildren (/Users/nick.heiner/.nvm/v0.11.14/lib/node_modules/tslint/bin/tslint-cli.js:41639:16)
    at NoUnusedVariablesWalker.SyntaxWalker.visitSourceFile (/Users/nick.heiner/.nvm/v0.11.14/lib/node_modules/tslint/bin/tslint-cli.js:41412:18)
    at NoUnusedVariablesWalker.SyntaxWalker.visitNode (/Users/nick.heiner/.nvm/v0.11.14/lib/node_modules/tslint/bin/tslint-cli.js:41603:26)
    at NoUnusedVariablesWalker.SyntaxWalker.walk (/Users/nick.heiner/.nvm/v0.11.14/lib/node_modules/tslint/bin/tslint-cli.js:41253:18)
    at Rule.AbstractRule.applyWithWalker (/Users/nick.heiner/.nvm/v0.11.14/lib/node_modules/tslint/bin/tslint-cli.js:41768:24)

TS 1.5 added the "Bare Import" syntax. I think that tslint just isn't supporting it.

TS docs screenshot

@adidahiya
Copy link
Contributor

@NickHeiner thanks for the detailed bug report. I'll update the title of this issue.

@adidahiya adidahiya changed the title Cannot read property 'name' of undefined no-unused-variable rule crashes on ES6 bare imports Jun 25, 2015
@adidahiya adidahiya assigned adidahiya and unassigned leeavital Jun 25, 2015
adidahiya added a commit that referenced this issue Jun 25, 2015
Fixes #451

This affects the following rules:

- `no-unused-variable`
- `no-use-before-declare`
- `whitespace` (it was already handled here, but I added a regression test)
@NickHeiner
Copy link
Contributor

Great! Would you mind publishing to npm so I can pick up the bugfix?

@adidahiya
Copy link
Contributor

@NickHeiner yes we're making a release now!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants