Skip to content
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

feat(parser): Draft of scope analysis with types #233

Closed
wants to merge 13 commits into from
Closed

feat(parser): Draft of scope analysis with types #233

wants to merge 13 commits into from

Conversation

armano2
Copy link
Member

@armano2 armano2 commented Feb 8, 2019

This is early stage of updated scope-analysis with types included into scope, there is still a lot to do.
Goal of this PR is to solve #18, #19, #21, #60, #207 #122, #249

@armano2 armano2 added enhancement New feature or request DO NOT MERGE PRs which should not be merged yet package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin package: parser Issues related to @typescript-eslint/parser breaking change This change will require a new major version to be released and removed package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin labels Feb 8, 2019
@armano2 armano2 self-assigned this Feb 9, 2019
@armano2

This comment has been minimized.

@armano2
Copy link
Member Author

armano2 commented Feb 11, 2019

i decided to split this PR to few smaller one (fixes for non types), and after they are going to be merged i will continue working on types

#244 #240 #237 #234

@armano2
Copy link
Member Author

armano2 commented Feb 13, 2019

looks like its working, we have to change logic in no-undef from eslint scope i have no access to global types defined by user or typescript, and there are false positives in this rule because of that:

const links = document.querySelectorAll( selector ) as NodeListOf<HTMLElement>

even if you specify globals for browser and es6 it will report that NodeListOf is not defined.

@typescript-eslint/core-team @mysticatea i will appreciate some feedback (and maybe some suggestions for tests)

@mysticatea
Copy link
Member

Amazing!

Hm. I have thought that we should use two ScopeManager instance for variables and types because variables and types are different concepts.

In TypeScript, a declaration creates entities in at least one of three groups: namespace, type, or value. Namespace-creating declarations create a namespace, which contains names that are accessed using a dotted notation. Type-creating declarations do just that: they create a type that is visible with the declared shape and bound to the given name. Lastly, value-creating declarations create values that are visible in the output JavaScript.
https://www.typescriptlang.org/docs/handbook/declaration-merging.html

Varaible references must not resolve to types and type references must not resolve to variables. Some entities such as classes and enums belong to both the variable scope and the type scope.

(so class A {} interface A {} is redeclaration.)

Therefore, my thought is a ScopeManager manages only variables and variable references for core rules, and another ScopeManager manages only types and type references in parserServices. (but I'm not sure if ScopeManager for types is needed because we can use TypeChecker of TS compiler API.)

If a single ScopeManager manages both, I think that scopes will have types and typeReferences, and the resolving logic connects variablesreferences and typestypeReferences.

Though, we need TypeChecker to know imported bindings belong to which area. :(


About variable rules in the plugin, I believe that we should deprecate those to avoid doing duplication. But If we decide to maintain those, I think that we should implement those with TypeChecker API rather than modifying core rules.

@armano2
Copy link
Member Author

armano2 commented Feb 15, 2019

hmm, this is good idea to split it, but i think it should be one ScopeManager with separated refferences and variables that we can share only some declarations between between types and variables

i will change this that scope has 2 types of references and core rules are going to work only for variables

i'm going to have to fix only no-unused-vars to check for types and other rules will have to be re-implemented for types.


no-unused-variables and other rules/checks witch can be done by tsc, can be migrated but only after we solve performance issue with creating programs...


even if we decide to leverage tsc as replacement for some of rules we still need scope for types to implement rules not supported by it.

no-shadow is good example, typescript is not warning user about this and this is great rule to catch some potential issues

class foo<T> {
  test<T>() {}
}

with this new implementation (splitting references) we should consider making no-shadow-types for this

thanks @mysticatea for this idea 👍

@JamesHenry
Copy link
Member

Please can we reopen this using the new WIP PR feature on GitHub?

@JamesHenry JamesHenry closed this Feb 23, 2019
kaicataldo pushed a commit to kaicataldo/typescript-eslint that referenced this pull request Aug 27, 2019
* Update eslint-docs

* Upgrade eslint-docs (take 2)
@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
breaking change This change will require a new major version to be released DO NOT MERGE PRs which should not be merged yet enhancement New feature or request package: parser Issues related to @typescript-eslint/parser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants