Skip to content

feat: no-implicit-globals supports exported block comment#16343

Merged
mdjermanovic merged 6 commits intoeslint:mainfrom
sosukesuzuki:fix-16327
Oct 14, 2022
Merged

feat: no-implicit-globals supports exported block comment#16343
mdjermanovic merged 6 commits intoeslint:mainfrom
sosukesuzuki:fix-16327

Conversation

@sosukesuzuki
Copy link
Copy Markdown
Contributor

@sosukesuzuki sosukesuzuki commented Sep 23, 2022

Prerequisites checklist

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

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

What changes did you make? (Give an overview)

Fixes #16327

Variables specified with /*exported variableName */ should not report errors by no-implicit-globals.

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

#16343 (comment)

@eslint-github-bot eslint-github-bot Bot added the triage An ESLint team member will look at this issue soon label Sep 23, 2022
@eslint-github-bot
Copy link
Copy Markdown

Hi @sosukesuzuki!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the message to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

@netlify
Copy link
Copy Markdown

netlify Bot commented Sep 23, 2022

Deploy Preview for docs-eslint ready!

Name Link
🔨 Latest commit 0c32702
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/634812c6fbbe0b0008bacaa6
😎 Deploy Preview https://deploy-preview-16343--docs-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@eslint-github-bot
Copy link
Copy Markdown

Hi @sosukesuzuki!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the message to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase

To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page.

Read more about contributing to ESLint here

@sosukesuzuki sosukesuzuki changed the title Rule Change: no-implicit-globals supports exported block comment feat: no-implicit-globals supports exported block comment Sep 23, 2022
@eslint-github-bot eslint-github-bot Bot added the feature This change adds a new feature to ESLint label Sep 23, 2022
Comment thread lib/linter/linter.js

if (variable) {
variable.eslintUsed = true;
variable.eslintExported = true;
Copy link
Copy Markdown
Contributor Author

@sosukesuzuki sosukesuzuki Sep 23, 2022

Choose a reason for hiding this comment

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

Here is a new property variable.eslintExported.
This represents the variable specified by the /* exported variableName */ comment (It represents export only unlike eslintUsed).

I'm not sure if this is a good. Is there a better way?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is the right approach. variable.eslintUsed could have been set to true by another rule via context.markVariableAsUsed(), so it's not a reliable indicator that the variable is intended to be used by other scripts, which is what we need in this rule and what /* exported */ means.

But, this is a change in the core so I'd like more opinions from @eslint/eslint-tsc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense to me.

@sosukesuzuki sosukesuzuki marked this pull request as ready for review September 23, 2022 18:27
@mdjermanovic mdjermanovic added rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Sep 23, 2022
@sosukesuzuki
Copy link
Copy Markdown
Contributor Author

Is there anything I should do to make progress on this?

Copy link
Copy Markdown
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

LGTM. Just one suggestion to clean things up a bit.

Comment thread lib/rules/no-implicit-globals.js Outdated
// Variables exported by "exported" block comments
const isExportedEslintVariables = variable.eslintExported;

if (isExportedEslintVariables) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We don’t need a variable here.

Suggested change
if (isExportedEslintVariables) {
if (variable.eslintExported) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done! 42ac8ae


var global_var = 42;
```

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
:::

To close ::: correct

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done! cdb5e89

Comment thread tests/lib/rules/no-implicit-globals.js Outdated
code: "/* exported foo */ var foo = function *foo() {};",
parserOptions: { ecmaVersion: 2015 }
},
"/* exported foo \n* exported bar */ var foo = 1, bar = 2;",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
"/* exported foo \n* exported bar */ var foo = 1, bar = 2;",
"/* exported foo, bar */ var foo = 1, bar = 2;",

This format is not supported. This directive would be parsed without errors, but the variables it declares as exported actually are: ["foo", "*", "exported", "bar"].

(the same for other tests with multiple exported variables)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done! c7b6c6a

//------------------------------------------------------------------------------
// exported
//------------------------------------------------------------------------------

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a test to confirm that exported does not allow variables that are implicitly created by assignments (global variable leaks). For example, /* exported foo */ foo = 1; should still be invalid for this rule.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done! 0c32702

Copy link
Copy Markdown
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!

@mdjermanovic mdjermanovic merged commit 28d1902 into eslint:main Oct 14, 2022
@sosukesuzuki sosukesuzuki deleted the fix-16327 branch October 14, 2022 15:52
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Oct 24, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [eslint](https://eslint.org) ([source](https://github.com/eslint/eslint)) | devDependencies | minor | [`8.25.0` -> `8.26.0`](https://renovatebot.com/diffs/npm/eslint/8.25.0/8.26.0) |

---

### Release Notes

<details>
<summary>eslint/eslint</summary>

### [`v8.26.0`](https://github.com/eslint/eslint/releases/tag/v8.26.0)

[Compare Source](eslint/eslint@v8.25.0...v8.26.0)

#### Features

-   [`4715787`](eslint/eslint@4715787) feat: check `Object.create()` in getter-return ([#&#8203;16420](eslint/eslint#16420)) (Yuki Hirasawa)
-   [`28d1902`](eslint/eslint@28d1902) feat: `no-implicit-globals` supports `exported` block comment ([#&#8203;16343](eslint/eslint#16343)) (Sosuke Suzuki)
-   [`e940be7`](eslint/eslint@e940be7) feat: Use ESLINT_USE_FLAT_CONFIG environment variable for flat config ([#&#8203;16356](eslint/eslint#16356)) (Tomer Aberbach)
-   [`dd0c58f`](eslint/eslint@dd0c58f) feat: Swap out Globby for custom globbing solution. ([#&#8203;16369](eslint/eslint#16369)) (Nicholas C. Zakas)

#### Bug Fixes

-   [`df77409`](eslint/eslint@df77409) fix: use `baseConfig` constructor option in FlatESLint ([#&#8203;16432](eslint/eslint#16432)) (Milos Djermanovic)
-   [`33668ee`](eslint/eslint@33668ee) fix: Ensure that glob patterns are matched correctly. ([#&#8203;16449](eslint/eslint#16449)) (Nicholas C. Zakas)
-   [`740b208`](eslint/eslint@740b208) fix: ignore messages without a `ruleId` in `getRulesMetaForResults` ([#&#8203;16409](eslint/eslint#16409)) (Francesco Trotta)
-   [`8f9759e`](eslint/eslint@8f9759e) fix: `--ignore-pattern` in flat config mode should be relative to `cwd` ([#&#8203;16425](eslint/eslint#16425)) (Milos Djermanovic)
-   [`325ad37`](eslint/eslint@325ad37) fix: make `getRulesMetaForResults` return a plain object in trivial case ([#&#8203;16438](eslint/eslint#16438)) (Francesco Trotta)
-   [`a2810bc`](eslint/eslint@a2810bc) fix: Ensure that directories can be unignored. ([#&#8203;16436](eslint/eslint#16436)) (Nicholas C. Zakas)
-   [`35916ad`](eslint/eslint@35916ad) fix: Ensure unignore and reignore work correctly in flat config. ([#&#8203;16422](eslint/eslint#16422)) (Nicholas C. Zakas)

#### Documentation

-   [`651649b`](eslint/eslint@651649b) docs: Core concepts page ([#&#8203;16399](eslint/eslint#16399)) (Ben Perlmutter)
-   [`631cf72`](eslint/eslint@631cf72) docs: note --ignore-path not supported with flat config ([#&#8203;16434](eslint/eslint#16434)) (Andy Edwards)
-   [`1692840`](eslint/eslint@1692840) docs: fix syntax in examples for new config files ([#&#8203;16427](eslint/eslint#16427)) (Milos Djermanovic)
-   [`d336cfc`](eslint/eslint@d336cfc) docs: Document extending plugin with new config ([#&#8203;16394](eslint/eslint#16394)) (Ben Perlmutter)

#### Chores

-   [`e917a9a`](eslint/eslint@e917a9a) ci: add node v19 ([#&#8203;16443](eslint/eslint#16443)) (Koichi ITO)
-   [`4b70b91`](eslint/eslint@4b70b91) chore: Add VS Code issues link ([#&#8203;16423](eslint/eslint#16423)) (Nicholas C. Zakas)
-   [`232d291`](eslint/eslint@232d291) chore: suppress a Node.js deprecation warning ([#&#8203;16398](eslint/eslint#16398)) (Koichi ITO)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzMi4yNDEuNSIsInVwZGF0ZWRJblZlciI6IjMyLjI0MS4xMCJ9-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1599
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
@eslint-github-bot eslint-github-bot Bot locked and limited conversation to collaborators Apr 13, 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 Apr 13, 2023
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 contributor pool feature This change adds a new feature to ESLint rule Relates to ESLint's core rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rule Change: no-implicit-globals should not report exported

3 participants