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

Type annotations being caught by space-infix-ops rule #4

Closed
JamesHenry opened this issue Jan 14, 2016 · 13 comments
Closed

Type annotations being caught by space-infix-ops rule #4

JamesHenry opened this issue Jan 14, 2016 · 13 comments
Labels

Comments

@JamesHenry
Copy link
Member

(Note: I am using ESLint via eslint-loader for webpack)
ESLint: 1.9.0
eslint-loader: 1.1.1
typescript-eslint-parser: 0.1.0-alpha-1

The following code shows how a variable, foo, can be explicitly annotated with type string
let foo: string = 'bar'

Currently this causes the space-infix-ops rule to error (if enabled).

Re-writing to:
let foo : string = 'bar'

...does fix the eslint error, and is technically not a TypeScript error (example).

However, I would argue that the vast majority of people write their annotations using the first form, and that is certainly what comes through in all the documentation and examples from Microsoft.

It would therefore not be the intention of users who have enabled the space-infix-ops rule to receive an error for let foo: string = 'bar'

@nzakas
Copy link
Member

nzakas commented Jan 15, 2016

Rules are going to behave strangely with TypeScript for a while; it's too early to start getting into making all the rules work (or making any changes to allow that).

In any event, there's nothing the parser could do to fix this, it would have to be some option in ESLint. Once the parsing is working correctly and the AST is filled out completely, we can circle back and look at what (if anything) can be done for failing rules.

@JamesHenry
Copy link
Member Author

Ok, that makes sense. Are there any resources you can point me at to get up to speed more quickly with how the AST is built, terminology etc?

I am super keen to help ESLint be a viable option for Angular 2 development, in particular, as I think we will be seeing a whole new wave of devs/teams embracing TypeScript, but I currently have no experience with linters/ASTs and would appreciate any ProTips!

@ilyavolodin
Copy link
Member

SpiderMonkey Parser API
Espree demo
Working with ESLint Rules
That should get you started.

@JamesHenry
Copy link
Member Author

Many thanks, @ilyavolodin!

@nzakas
Copy link
Member

nzakas commented Jan 16, 2016

@alberto
Copy link
Member

alberto commented Jan 16, 2016

Thanks @nzakas, that's super useful!

@mysticatea
Copy link
Member

http://astexplorer.net/

@JamesHenry
Copy link
Member Author

👍

@aqzhyi
Copy link

aqzhyi commented May 20, 2016

Hi, Is this issue have any update?

@nzakas
Copy link
Member

nzakas commented May 21, 2016

@Pleasurazy the issue is closed. This project is still experimental and is expected to have a lot of errors at this point. As such, we are not accepting bug reports at this time.

@AdamWillden
Copy link

As this parseris now at 1.0.0 are we free to submit bug reports such as this? Can this be reopened?

@JamesHenry
Copy link
Member Author

@AdamWillden it is not a bug in this project (i.e. it is not problem with the parsing or the generated AST), so this will not be reopened.

The rule in ESLint core will need to be extended to take typeAnnotation nodes into account, as mentioned here #77 (comment)

@AdamWillden
Copy link

@JamesHenry thanks for linking the two. Makes sense!

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

8 participants