Description
Which packages would you like to change?
-
espree
-
eslint-scope
-
eslint-visitor-keys
What problem do you want to solve?
There are a lot of ESLint rules that need to determine if a given identifier refers to a global or not. As a result, we have multiple copies of functions that try to determine if an identifier refers to a global:
https://github.com/search?q=repo%3Aeslint%2Feslint%20isglobal&type=code
That also means plugin rules need to implement their own.
What do you think is the correct solution?
I think this is common enough that we should add a isGlobalReference()
method to ScopeManager
to encapsulate this functionality:
const isGlobal = scopeManager.isGlobalScope(node);
I think the method should accept a node and then determine from that node if it contains a reference to a global variable. Basically, we can copy the code from here:
Then maybe we could expose the method on SourceCode
to make it easier for rules to access.
Participation
- I am willing to submit a pull request for this change.
Additional comments
Looking for a volunteer to take this on.
Metadata
Metadata
Assignees
Type
Projects
Status