Skip to content

Commit 5a4324f

Browse files
authored
docs: clarify "local" option of no-unused-vars (#20385)
1 parent b017f09 commit 5a4324f

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

docs/src/rules/no-unused-vars.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ By default this rule is enabled with `all` option for caught errors and variable
153153

154154
The `vars` option has two settings:
155155

156-
* `all` checks all variables for usage, including those in the global scope. However, it excludes variables targeted by other options like `args` and `caughtErrors`. This is the default setting.
157-
* `local` checks only that locally-declared variables are used but will allow global variables to be unused.
156+
* `"all"` checks all variables for usage, including those in the global scope. However, it excludes variables targeted by other options like `args` and `caughtErrors`. This is the default setting.
157+
* `"local"` allows variables in the global scope to be unused.
158158

159159
#### vars: local
160160

@@ -171,6 +171,26 @@ some_unused_var = 42;
171171

172172
:::
173173

174+
Examples of **correct** code for the `{ "vars": "local" }` option with `"languageOptions": { "sourceType": "script" }`:
175+
176+
::: correct { "sourceType": "script" }
177+
178+
```js
179+
/*eslint no-unused-vars: ["error", { "vars": "local" }]*/
180+
181+
const foo = 42;
182+
183+
let bar;
184+
185+
let baz = 42;
186+
187+
var qux;
188+
189+
var quux = 42;
190+
```
191+
192+
:::
193+
174194
### varsIgnorePattern
175195

176196
The `varsIgnorePattern` option specifies exceptions not to check for usage: variables whose names match a regexp pattern. For example, variables whose names contain `ignored` or `Ignored`. However, it excludes variables targeted by other options like `argsIgnorePattern` and `caughtErrorsIgnorePattern`.

0 commit comments

Comments
 (0)