8000 Rule Propsal: No generic type variable shadowing · Issue #521 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

Rule Propsal: No generic type variable shadowing #521

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

Closed
nmain opened this issue May 13, 2019 · 4 comments
Closed

Rule Propsal: No generic type variable shadowing #521

nmain opened this issue May 13, 2019 · 4 comments
Labels
enhancement: new plugin rule New rule request for eslint-plugin package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@nmain
Copy link
nmain commented May 13, 2019

Example code:

class Foo<T> {
    bar<T>() {
        // here, T refers to the T for bar, not the T for Foo
    }
}

A rule could ban instances where a generic type variable is introduced with the same name as one in the enclosing scope. Related to #54

@nmain nmain added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels May 13, 2019
@bradzacher
Copy link
Member

ideally this would be patched into the base rule https://eslint.org/docs/rules/no-shadow instead of creating a brand new rule for this case.

@bradzacher bradzacher added enhancement: new base rule extension New base rule extension required to handle a TS specific case and removed triage Waiting for team members to take a look labels May 13, 2019
@mysticatea
Copy link
Member

TypeScript has two namespace; variables and types. The same name can exist each other, and it's not shadowing.

The no-shadow core rule handles variables. I think that another rule is needed for types.

@bradzacher
Copy link
Member

Technically for typescript there's 2 and a half scopes - variables, types, and variable types (enums and classes I think are the only two that fit into this).

Correct me if I'm wrong - but no-shadow relies upon scope analysis?
@armano2 was working on rewriting the scope analyser so it correctly tracked typescript's multiple scopes.

If that works correctly, then no-shadow should work as expected without any modifications (as would other rules that rely upon scope analysis like no-unused-vars, etc).

@mysticatea
Copy link
Member
mysticatea commented May 13, 2019

No. classes and enums just belong to both at the same time. There is not the third kind of namespaces. After the correct scope analysis arrived, no-shadow rule would verify only the variable space.

@bradzacher bradzacher added enhancement: new plugin rule New rule request for eslint-plugin and removed enhancement: new base rule extension New base rule extension required to handle a TS specific case labels May 13, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: new plugin rule New rule request for eslint-plugin package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

3 participants
0