You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/rules/one-var.md
+85-17Lines changed: 85 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,7 @@ title: one-var
3
3
rule_type: suggestion
4
4
---
5
5
6
-
7
-
8
-
Variables can be declared at any point in JavaScript code using `var`, `let`, or `const`. There are many styles and preferences related to the declaration of variables, and one of those is deciding on how many variable declarations should be allowed in a single function.
6
+
Variables can be declared at any point in JavaScript code using `var`, `let`, `const`, `using`, or `await using`. There are many styles and preferences related to the declaration of variables, and one of those is deciding on how many variable declarations should be allowed in a single function.
9
7
10
8
There are two schools of thought in this regard:
11
9
@@ -31,7 +29,7 @@ The single-declaration school of thought is based in pre-ECMAScript 6 behaviors,
31
29
32
30
## Rule Details
33
31
34
-
This rule enforces variables to be declared either together or separately per function ( for `var`) or block (for `let`and `const`) scope.
32
+
This rule enforces variables to be declared either together or separately per function ( for `var`) or block (for `let`, `const`, `using`, and `await using`) scope.
35
33
36
34
## Options
37
35
@@ -54,6 +52,12 @@ Object option:
54
52
*`"const": "always"` requires one `const` declaration per block
55
53
*`"const": "never"` requires multiple `const` declarations per block
56
54
*`"const": "consecutive"` requires consecutive `const` declarations to be a single declaration
55
+
*`"using": "always"` requires one `using` declaration per block
56
+
*`"using": "never"` requires multiple `using` declarations per block
57
+
*`"using": "consecutive"` requires consecutive `using` declarations to be a single declaration
58
+
*`"awaitUsing": "always"` requires one `await using` declaration per block
59
+
*`"awaitUsing": "never"` requires multiple `await using` declarations per block
60
+
*`"awaitUsing": "consecutive"` requires consecutive `await using` declarations to be a single declaration
57
61
*`"separateRequires": true` enforces `requires` to be separate from declarations
58
62
59
63
Alternate object option:
@@ -339,14 +343,14 @@ class C {
339
343
340
344
:::
341
345
342
-
### var, let, and const
346
+
### var, let, const, using, and awaitUsing
343
347
344
-
Examples of **incorrect** code for this rule with the `{ var: "always", let: "never", const: "never" }` option:
348
+
Examples of **incorrect** code for this rule with the `{ var: "always", let: "never", const: "never", using: "never", awaitUsing: "never" }` option:
@@ -411,17 +429,23 @@ Examples of **correct** code for this rule with the `{ var: "never" }` option:
411
429
```js
412
430
/*eslint one-var: ["error", { var: "never" }]*/
413
431
414
-
functionfoo() {
432
+
asyncfunctionfoo() {
415
433
var bar;
416
434
var baz;
417
435
418
-
// `const`and `let` declarations are ignored if they are not specified
436
+
// `const`, `let`, `using` and `await using` declarations are ignored if they are not specified
419
437
constfoobar=1;
420
438
constfoobaz=2;
421
439
constbarfoo=1, bazfoo =2;
422
440
let qux;
423
441
let norf;
424
442
let fooqux, foonorf;
443
+
using foobarfoo =1;
444
+
using foobazfoo =2;
445
+
using bazbarfoo =1, bazfoobar =2;
446
+
await using foobarbaz =1;
447
+
await using foobazqux =2;
448
+
await using bazbarqux =1, bazfooqux =2;
425
449
}
426
450
```
427
451
@@ -464,12 +488,12 @@ var foo = require("foo"),
464
488
465
489
:::
466
490
467
-
Examples of **incorrect** code for this rule with the `{ var: "never", let: "consecutive", const: "consecutive" }` option:
491
+
Examples of **incorrect** code for this rule with the `{ var: "never", let: "consecutive", const: "consecutive", using: "consecutive", awaitUsing: "consecutive" }` option:
Examples of **correct** code for this rule with the `{ var: "never", let: "consecutive", const: "consecutive" }` option:
537
+
Examples of **correct** code for this rule with the `{ var: "never", let: "consecutive", const: "consecutive", using: "consecutive", awaitUsing: "consecutive" }` option:
0 commit comments