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

Fix: api.markVariableAsUsed should check Node.js scope (fixes #2089) #2090

Closed
wants to merge 1 commit into from

Conversation

yannickcr
Copy link
Contributor

Fix very similar to the one you've done for #2064

I also added a test to reproduce the problem and fixed the getVariable helper to also check the Node.js scope.


found = markVariableAsUsedInScope(scope);

if (!found && scope.childScopes.length) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is overly aggressive because there's only one time when we want to check the first child. You really want to check if scope.type is "global" and only do this next step if that's true.

@yannickcr
Copy link
Contributor Author

Has requested, I updated the condition to be less aggressive.

variables[i].eslintUsed = true;
return true;
found = false;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a much more appropriate change to make here. This could cause the wrong variable to be marked because it searches global and then node scope, which is the opposite of how variable resolution works.

Instead, this can be added to the original code just before the loop:

if (scope.type === "global" && currentConfig.ecmaFeatures.globalReturn) {
    scope = scope.childScopes[0];
}

@nzakas
Copy link
Member

nzakas commented Mar 21, 2015

Closing in favor of #2121

@nzakas nzakas closed this Mar 21, 2015
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 7, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants