From 383e99928d7ce649ec9030c9856b03fbac0c3501 Mon Sep 17 00:00:00 2001 From: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> Date: Fri, 24 Nov 2023 14:46:35 +0530 Subject: [PATCH] docs: update and fix examples for `no-unused-vars` (#17788) * docs: update and fix examples for no-unused-var * docs: update previous changes --- docs/src/rules/no-unused-vars.md | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/src/rules/no-unused-vars.md b/docs/src/rules/no-unused-vars.md index 1b3e59ce93b..f88b1ccb307 100644 --- a/docs/src/rules/no-unused-vars.md +++ b/docs/src/rules/no-unused-vars.md @@ -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,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; @@ -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); ``` :::