From 9db7f203cca5af30e1069be503f262207f621f7f Mon Sep 17 00:00:00 2001 From: Tanuj Kanti Date: Thu, 23 Nov 2023 23:02:29 +0530 Subject: [PATCH 1/2] docs: update and fix examples for no-unused-var --- docs/src/rules/no-unused-vars.md | 40 ++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/docs/src/rules/no-unused-vars.md b/docs/src/rules/no-unused-vars.md index 1b3e59ce93b..bda20da35b5 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,13 +107,25 @@ 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 ```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 + var global_var = 42; ``` @@ -119,9 +133,19 @@ 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 { @@ -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); ``` ::: From 2aaf542aa99c50e791067ab3577461297422fc09 Mon Sep 17 00:00:00 2001 From: Tanuj Kanti Date: Fri, 24 Nov 2023 08:16:01 +0530 Subject: [PATCH 2/2] docs: update previous changes --- docs/src/rules/no-unused-vars.md | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/docs/src/rules/no-unused-vars.md b/docs/src/rules/no-unused-vars.md index bda20da35b5..f88b1ccb307 100644 --- a/docs/src/rules/no-unused-vars.md +++ b/docs/src/rules/no-unused-vars.md @@ -113,19 +113,14 @@ The line comment `// exported variableName` will not work as `exported` is not l var global_var = 42; ``` -Examples of **correct** code for `/* exported variableName */` operation with `no-unused-var`: +Examples of **correct** code for `/* exported variableName */` operation with `no-unused-vars`: -::: correct +::: correct { "sourceType": "script" } ```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 - var global_var = 42; ``` @@ -133,19 +128,9 @@ var global_var = 42; ## Options -This rule takes one argument which can be a string or an object. +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). -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. +By default this rule is enabled with `all` option for variables and `after-used` for arguments. ```json { @@ -155,8 +140,6 @@ Object setting has several options. } ``` -By default this rule is enabled with `all` option for variables and `after-used` for arguments. - ### vars The `vars` option has two settings: