useSingleVarDeclarator
诊断类别:lint/style/useSingleVarDeclarator
¥Diagnostic Category: lint/style/useSingleVarDeclarator
自从:v1.0.0
¥Since: v1.0.0
来源:
¥Sources:
禁止在同一个变量语句中声明多个变量
¥Disallow multiple variable declarations in the same variable statement
在 JavaScript 中,可以在单个 var
、const
或 let
声明中声明多个变量。通常认为,最好分别声明每个变量。这就是此规则所强制执行的。
¥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
¥Invalid
code-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 │
¥Valid
¥Related links