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

Rule Change: no-implicit-globals lexicalBindings without functions #16328

Closed
kkmuffme opened this issue Sep 18, 2022 · 1 comment
Closed

Rule Change: no-implicit-globals lexicalBindings without functions #16328

kkmuffme opened this issue Sep 18, 2022 · 1 comment
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects

Comments

@kkmuffme
Copy link

kkmuffme commented Sep 18, 2022

What rule do you want to change?

no-implicit-globals

What change to do you want to make?

Implement suggestions

How do you think the change should be implemented?

A new option

Example code

/**
 * @returns {int}
 */
function testFunc() {
    "use strict";

    return 1 + 2;
}

What does the rule currently do for this code?

When using with lexicalBindings /*eslint no-implicit-globals: ["error", {"lexicalBindings": true}]*/ it gives an error

What will the rule do after it's changed?

Not report an error for functions in global context.
e.g. if there was an option for that like:
/*eslint no-implicit-globals: ["error", {"lexicalBindingsVars": true}]*/

to only apply it to const/let, or alternatively a different value ('only-variables' or 'no-functions'):
/*eslint no-implicit-globals: ["error", {"lexicalBindings": "no-functions"}]*/
or
/*eslint no-implicit-globals: ["error", {"lexicalBindings": "only-variables"}]*/

@kkmuffme kkmuffme added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules labels Sep 18, 2022
@eslint-github-bot eslint-github-bot bot added this to Needs Triage in Triage Sep 18, 2022
@mdjermanovic
Copy link
Member

The lexicalBindings option doesn't relate to functions. This rule checks and reports functions by default, regardless of this option, here's an example in eslint playground. The lexicalBindings option is intended to include lexical bindings (not to exclude others), and was added for backward compatibility reasons only. This rule should actually always report all declarations that create global variables, and I don't think there should be an option to exclude all function declarations. I'm more in favor of marking individual declarations as intentionally global, as proposed in #16327.

Triage automation moved this from Needs Triage to Complete Sep 19, 2022
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Mar 19, 2023
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Mar 19, 2023
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 enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
Archived in project
Triage
Complete
Development

No branches or pull requests

2 participants