feat: no-implicit-globals supports exported block comment#16343
feat: no-implicit-globals supports exported block comment#16343mdjermanovic merged 6 commits intoeslint:mainfrom
no-implicit-globals supports exported block comment#16343Conversation
|
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.
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 |
✅ Deploy Preview for docs-eslint ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
c9ae910 to
313a17b
Compare
|
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.
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 |
no-implicit-globals supports exported block commentno-implicit-globals supports exported block comment
|
|
||
| if (variable) { | ||
| variable.eslintUsed = true; | ||
| variable.eslintExported = true; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
|
Is there anything I should do to make progress on this? |
nzakas
left a comment
There was a problem hiding this comment.
LGTM. Just one suggestion to clean things up a bit.
| // Variables exported by "exported" block comments | ||
| const isExportedEslintVariables = variable.eslintExported; | ||
|
|
||
| if (isExportedEslintVariables) { |
There was a problem hiding this comment.
We don’t need a variable here.
| if (isExportedEslintVariables) { | |
| if (variable.eslintExported) { |
|
|
||
| var global_var = 42; | ||
| ``` | ||
|
|
There was a problem hiding this comment.
| ::: | |
To close ::: correct
| code: "/* exported foo */ var foo = function *foo() {};", | ||
| parserOptions: { ecmaVersion: 2015 } | ||
| }, | ||
| "/* exported foo \n* exported bar */ var foo = 1, bar = 2;", |
There was a problem hiding this comment.
| "/* 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)
| //------------------------------------------------------------------------------ | ||
| // exported | ||
| //------------------------------------------------------------------------------ | ||
|
|
There was a problem hiding this comment.
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.
test: add valid tests test: add invalid tests
docs: add correct example
313a17b to
0c32702
Compare
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 ([#​16420](eslint/eslint#16420)) (Yuki Hirasawa) - [`28d1902`](eslint/eslint@28d1902) feat: `no-implicit-globals` supports `exported` block comment ([#​16343](eslint/eslint#16343)) (Sosuke Suzuki) - [`e940be7`](eslint/eslint@e940be7) feat: Use ESLINT_USE_FLAT_CONFIG environment variable for flat config ([#​16356](eslint/eslint#16356)) (Tomer Aberbach) - [`dd0c58f`](eslint/eslint@dd0c58f) feat: Swap out Globby for custom globbing solution. ([#​16369](eslint/eslint#16369)) (Nicholas C. Zakas) #### Bug Fixes - [`df77409`](eslint/eslint@df77409) fix: use `baseConfig` constructor option in FlatESLint ([#​16432](eslint/eslint#16432)) (Milos Djermanovic) - [`33668ee`](eslint/eslint@33668ee) fix: Ensure that glob patterns are matched correctly. ([#​16449](eslint/eslint#16449)) (Nicholas C. Zakas) - [`740b208`](eslint/eslint@740b208) fix: ignore messages without a `ruleId` in `getRulesMetaForResults` ([#​16409](eslint/eslint#16409)) (Francesco Trotta) - [`8f9759e`](eslint/eslint@8f9759e) fix: `--ignore-pattern` in flat config mode should be relative to `cwd` ([#​16425](eslint/eslint#16425)) (Milos Djermanovic) - [`325ad37`](eslint/eslint@325ad37) fix: make `getRulesMetaForResults` return a plain object in trivial case ([#​16438](eslint/eslint#16438)) (Francesco Trotta) - [`a2810bc`](eslint/eslint@a2810bc) fix: Ensure that directories can be unignored. ([#​16436](eslint/eslint#16436)) (Nicholas C. Zakas) - [`35916ad`](eslint/eslint@35916ad) fix: Ensure unignore and reignore work correctly in flat config. ([#​16422](eslint/eslint#16422)) (Nicholas C. Zakas) #### Documentation - [`651649b`](eslint/eslint@651649b) docs: Core concepts page ([#​16399](eslint/eslint#16399)) (Ben Perlmutter) - [`631cf72`](eslint/eslint@631cf72) docs: note --ignore-path not supported with flat config ([#​16434](eslint/eslint#16434)) (Andy Edwards) - [`1692840`](eslint/eslint@1692840) docs: fix syntax in examples for new config files ([#​16427](eslint/eslint#16427)) (Milos Djermanovic) - [`d336cfc`](eslint/eslint@d336cfc) docs: Document extending plugin with new config ([#​16394](eslint/eslint#16394)) (Ben Perlmutter) #### Chores - [`e917a9a`](eslint/eslint@e917a9a) ci: add node v19 ([#​16443](eslint/eslint#16443)) (Koichi ITO) - [`4b70b91`](eslint/eslint@4b70b91) chore: Add VS Code issues link ([#​16423](eslint/eslint#16423)) (Nicholas C. Zakas) - [`232d291`](eslint/eslint@232d291) chore: suppress a Node.js deprecation warning ([#​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>
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 byno-implicit-globals.Is there anything you'd like reviewers to focus on?
#16343 (comment)