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
docs: remove /* eslint-env */
comments from rule examples
#18249
Conversation
✅ Deploy Preview for docs-eslint canceled.
|
Examples of **incorrect** code for the `{ "builtinGlobals": true }` option and the `browser` environment: | ||
|
||
::: incorrect { "sourceType": "script" } | ||
|
||
```js | ||
/*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/ | ||
/*eslint-env browser*/ | ||
|
||
var top = 0; | ||
``` | ||
|
||
::: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example would require specifying global variable in the config (/* global */
comment wouldn't do the work, it's a different check). Since our Playground doesn't support specifying globals, I removed this example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replacing /*eslint-env browser*/
with /*global top*/
does actually produce an incorrect example (repro). "builtinGlobals": true
isn't even necessary. When you say it wouldn't work it's because it wouldn't report on the declaration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's a different kind of error. /*global top*/
is reported as redundant because the variable is declared in the code, whereas this example aimed to show an attempt to declare a variable that already exists.
Examples of **incorrect** code for the `{ "builtinGlobals": true }` option and the `browser` environment: | ||
|
||
::: incorrect { "sourceType": "script" } | ||
|
||
```js | ||
/*eslint no-redeclare: ["error", { "builtinGlobals": true }]*/ | ||
/*eslint-env browser*/ | ||
|
||
var top = 0; | ||
``` | ||
|
||
::: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replacing /*eslint-env browser*/
with /*global top*/
does actually produce an incorrect example (repro). "builtinGlobals": true
isn't even necessary. When you say it wouldn't work it's because it wouldn't report on the declaration?
Co-authored-by: Francesco Trotta <github@fasttime.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
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)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
/* eslint-env */
have no effect in flat config mode. This PR removes those comments from rule examples.What changes did you make? (Give an overview)
/* eslint-env */
comments totools/check-rule-examples.js
/* eslint-env */
comments from rule examples."latest"
, I just removed them.browser
ornode
environments to enable specific globals. I replaced those comments with/* global */
comments.Is there anything you'd like reviewers to focus on?