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: update and fix examples for no-unused-vars
#17788
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -56,6 +56,7 @@ function fact(n) { | |||||||||
function getY([x, y]) { | ||||||||||
return y; | ||||||||||
} | ||||||||||
getY(["a", "b"]); | ||||||||||
``` | ||||||||||
|
||||||||||
::: | ||||||||||
|
@@ -89,6 +90,7 @@ myFunc = setTimeout(function() { | |||||||||
function getY([, y]) { | ||||||||||
return y; | ||||||||||
} | ||||||||||
getY(["a", "b"]); | ||||||||||
``` | ||||||||||
|
||||||||||
::: | ||||||||||
|
@@ -105,23 +107,45 @@ Note that `/* exported */` has no effect for any of the following: | |||||||||
|
||||||||||
The line comment `// exported variableName` will not work as `exported` is not line-specific. | ||||||||||
|
||||||||||
Examples of **correct** code for `/* exported variableName */` operation: | ||||||||||
```js | ||||||||||
/* exported global_var */ | ||||||||||
|
||||||||||
var global_var = 42; | ||||||||||
``` | ||||||||||
|
||||||||||
Examples of **correct** code for `/* exported variableName */` operation with `no-unused-var`: | ||||||||||
|
||||||||||
::: correct | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We can add this config to make the example valid in the Playground. |
||||||||||
|
||||||||||
```js | ||||||||||
/*eslint no-unused-vars: "error"*/ | ||||||||||
/* exported global_var */ | ||||||||||
|
||||||||||
// rule will not report global_var | ||||||||||
// sourcType must be set to script | ||||||||||
// environment should not be node or commonjs | ||||||||||
// globalReturn must be set to false | ||||||||||
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think there's no need for additional comments because the ESLint configuration with which this will be valid is already explained at the beginning of this section. I'm guessing you added this as instructions on how to configure the Playground for this example to be valid, but with the configuration we'll pass to the Playground (#17788 (comment)) it will be valid right away. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||||||||||
var global_var = 42; | ||||||||||
``` | ||||||||||
|
||||||||||
::: | ||||||||||
|
||||||||||
## Options | ||||||||||
|
||||||||||
This rule takes one argument which can be a string or an object. The string settings are the same as those of the `vars` property (explained below). | ||||||||||
This rule takes one argument which can be a string or an object. | ||||||||||
|
||||||||||
By default this rule is enabled with `all` option for variables and `after-used` for arguments. | ||||||||||
String setting has two possible modes `all` and `local` to allow global and local variables (works similar as `vars` option explained below). | ||||||||||
|
||||||||||
```json | ||||||||||
{ | ||||||||||
"rules": { | ||||||||||
"no-unused-vars": ["error", "local"] | ||||||||||
} | ||||||||||
} | ||||||||||
``` | ||||||||||
|
||||||||||
Object setting has several options. | ||||||||||
|
||||||||||
```json | ||||||||||
{ | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this section was fine and seems better to leave it as is. The description of string settings refers to the |
||||||||||
|
@@ -131,6 +155,8 @@ By default this rule is enabled with `all` option for variables and `after-used` | |||||||||
} | ||||||||||
``` | ||||||||||
|
||||||||||
By default this rule is enabled with `all` option for variables and `after-used` for arguments. | ||||||||||
|
||||||||||
### vars | ||||||||||
|
||||||||||
The `vars` option has two settings: | ||||||||||
|
@@ -386,11 +412,15 @@ Examples of **correct** code for the `{ "ignoreRestSiblings": true }` option: | |||||||||
|
||||||||||
```js | ||||||||||
/*eslint no-unused-vars: ["error", { "ignoreRestSiblings": true }]*/ | ||||||||||
|
||||||||||
// 'foo' and 'bar' were ignored because they have a rest property sibling. | ||||||||||
var { foo, ...coords } = data; | ||||||||||
var { foo, ...rest } = data; | ||||||||||
console.log(rest); | ||||||||||
|
||||||||||
// OR | ||||||||||
|
||||||||||
var bar; | ||||||||||
({ bar, ...coords } = data); | ||||||||||
({ bar, ...rest } = data); | ||||||||||
``` | ||||||||||
|
||||||||||
::: | ||||||||||
|
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.