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

docs: update and fix examples for no-unused-vars #17788

Merged
merged 2 commits into from Nov 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 17 additions & 4 deletions docs/src/rules/no-unused-vars.md
Expand Up @@ -56,6 +56,7 @@ function fact(n) {
function getY([x, y]) {
return y;
}
getY(["a", "b"]);
```

:::
Expand Down Expand Up @@ -89,6 +90,7 @@ myFunc = setTimeout(function() {
function getY([, y]) {
return y;
}
getY(["a", "b"]);
```

:::
Expand All @@ -105,11 +107,18 @@ 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 */

::: correct
var global_var = 42;
```

Examples of **correct** code for `/* exported variableName */` operation with `no-unused-vars`:

::: correct { "sourceType": "script" }

```js
/*eslint no-unused-vars: "error"*/
/* exported global_var */

var global_var = 42;
Expand Down Expand Up @@ -386,11 +395,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);
```

:::
Expand Down