useSingleVarDeclarator
此内容尚不支持你的语言。
Diagnostic Category: lint/style/useSingleVarDeclarator
Since: v1.0.0
Sources:
- Same as:
one-var
Disallow multiple variable declarations in the same variable statement
In JavaScript, multiple variables can be declared within a single var
, const
or let
declaration.
It is often considered a best practice to declare every variable separately.
That is what this rule enforces.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.js:1:1 lint/style/useSingleVarDeclarator FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Declare variables separately
> 1 │ let foo = 0, bar, baz;
│ ^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Unsafe fix: Break out into multiple declarations
1 │ - let·foo·=·0,·bar,·baz;
1 │ + let·foo·=·0;
2 │ + let·bar;
3 │ + let·baz;
2 4 │