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

Chore: rename shadowed global #12862

Merged
merged 1 commit into from Feb 4, 2020
Merged

Chore: rename shadowed global #12862

merged 1 commit into from Feb 4, 2020

Conversation

UziTech
Copy link
Contributor

@UziTech UziTech commented Feb 2, 2020

Prerequisites checklist

  • I have read the contributing guidelines.
  • The team has reached consensus on the changes proposed in this pull request. If not, I understand that the evaluation process will begin with this pull request and won't be merged until the team has reached consensus.

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

Tell us about your environment

  • ESLint Version: 6.8.0
  • Node Version: 12.13.0
  • npm Version: 6.13.7

What did you do? Please include the actual source code causing the issue.

use rollup to include eslint in the browser

What did you expect to happen?

bundle eslint/lib/linter/linter.js

What actually happened? Please include the actual, raw output from ESLint.

rollup error:

[!] Error: Unexpected token
node_modules\eslint\lib\rules\no-obj-calls.js (50:33)
48:                 const traceMap = {};
49:
50:                 for (const global of nonCallableGlobals) {
                                     ^
51:                     traceMap[global] = {
52:                         [CALL]: true

What changes did you make? (Give an overview)

rename variable global to g

Is there anything you'd like reviewers to focus on?

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Feb 2, 2020
@mdjermanovic mdjermanovic added chore This change is not user-facing evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Feb 2, 2020
@mdjermanovic
Copy link
Member

I'm not against this change if it would help, but as far as I know global isn't a reserved word.

I believe this could be a bug in @rollup/plugin-commonjs as the code on which the parser throws seems to be the following:

for (const commonjsHelpers.commonjsGlobal of nonCallableGlobals) {
    traceMap[commonjsHelpers.commonjsGlobal] = {
        [CALL]: true
    }; 
}

It looks like the local global variable was transformed as if it was the Node's global. This doesn't happen if the plugin is used with commonjs({ ignoreGlobal: true }).

@ljharb
Copy link
Sponsor Contributor

ljharb commented Feb 2, 2020

global is very much not a reserved word.

@mdjermanovic
Copy link
Member

I'm anyway 👍 to rename this variable because it's shadowing the global global, in order to avoid possible errors if the code gets changed in the future.

@UziTech
Copy link
Contributor Author

UziTech commented Feb 3, 2020

commonjs({ ignoreGlobal: true }) did work to prevent the error in rollup, but I agree shadowing the global variable might have unintended effects in the future.

@mdjermanovic
Copy link
Member

commonjs({ ignoreGlobal: true }) did work to prevent the error in rollup, but I agree shadowing the global variable might have unintended effects in the future.

Though, { ignoreGlobal: true } might break something else. It might be good to anyway open an issue at https://github.com/rollup/plugins since this does look like a bug in the plugin.

@kaicataldo kaicataldo added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Feb 3, 2020
@kaicataldo
Copy link
Member

Marking as accepted as I do think it's best not to shadow Node's global object. We should change the commit message. Maybe Chore: rename shadowed global?

@UziTech UziTech changed the title Fix: global is a reserved word Chore: rename shadowed global Feb 3, 2020
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Copy link
Member

@platinumazure platinumazure left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@kaicataldo kaicataldo merged commit 0cae920 into eslint:master Feb 4, 2020
@kaicataldo
Copy link
Member

Thanks for contributing!

montmanu pushed a commit to montmanu/eslint that referenced this pull request Mar 4, 2020
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Aug 4, 2020
@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 Aug 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion chore This change is not user-facing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants