Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Parser cannot parse inside decoration syntax #55

Closed
okunokentaro opened this issue Aug 15, 2016 · 12 comments
Closed

Parser cannot parse inside decoration syntax #55

okunokentaro opened this issue Aug 15, 2016 · 12 comments
Labels

Comments

@okunokentaro
Copy link

import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {AppComponent} from './app.component';

@NgModule({
  imports: [
    BrowserModule
  ],
  declarations: [
    AppComponent
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}
  1:9  warning  'NgModule' is defined but never used       no-unused-vars
  2:9  warning  'BrowserModule' is defined but never used  no-unused-vars
  3:9  warning  'AppComponent' is defined but never used   no-unused-vars

I'm using in [email protected] and [email protected]. typescript-eslint-parser cannot perse the decorators syntax and inside the @NgModule() argument object. It was displayed no-unused-vars in spite of actually it's using inside argument.

@nzakas
Copy link
Member

nzakas commented Aug 15, 2016

It looks like it is being parsed fine, it's just triggering linting errors. This is expected right now because ESLint doesn't understand decorator semantics. I'll leave this open to track, but the fix wont be in the parser.

@okunokentaro
Copy link
Author

I see, thank you. I expect in the future.

@mysticatea
Copy link
Member

@nzakas
Copy link
Member

nzakas commented Aug 19, 2016

Yeah, there's no way we are going to do that here. :)

@nzakas
Copy link
Member

nzakas commented Aug 22, 2016

Actually, it looks like we aren't even attaching the decorators into the AST. @JamesHenry do you have time to look into that?

@JamesHenry
Copy link
Member

I actually thought about this for a bit after Alex submitted his issue :) I could not find any reference to ESTree or Flow capturing decorators though. Shall I go for whatever the TypeScript vernacular is for now?

@JamesHenry
Copy link
Member

I have opened up a new issue to track adding decorators to the final AST: #63

@JamesHenry
Copy link
Member

JamesHenry commented Aug 25, 2016

@nzakas Just to confirm, even now that we have added the class decorators to the AST, the no-unused-var errors are still present.

I guess this will be solved in the plugin?

@nzakas
Copy link
Member

nzakas commented Aug 26, 2016

Yes, that's behavior is expected because escope doesn't know how to handle decorators.

@JamesHenry
Copy link
Member

Have you had any thoughts about how we might address that for this case? I am very happy to work on a fix for this, but so far it's not clear to me how/where this will be tackled.

@nzakas
Copy link
Member

nzakas commented Aug 26, 2016

In the short-term, we can probably add a rule in eslint-plugin-typescript that manually marks the identifier as used. eslint-plugin-react had to do something similar for some JSX stuff: https://github.com/yannickcr/eslint-plugin-react/blob/master/lib/rules/jsx-uses-vars.js

@JamesHenry
Copy link
Member

I am going to close this as it is neither a bug, nor a feature that relates to this project specifically.

To summarise:

TypeScript decorator syntax is fully supported by this parser, but there is not yet a way for the ESLint core rule no-unused-vars to know when they have actually been used.

This detection mechanism will be implemented in the complementary project eslint-plugin-typescript and you can track the progress here: bradzacher/eslint-plugin-typescript#2

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

No branches or pull requests

5 participants