useSingleVarDeclarator
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/style/useSingleVarDeclarator¥Diagnostic Category:
lint/style/useSingleVarDeclarator -
此规则包含 unsafe 修复程序。
¥This rule has an unsafe fix.
-
此规则的默认严重级别为 information。
¥The default severity of this rule is information.
-
来源:
¥Sources:
¥How to configure
{ "linter": { "rules": { "style": { "useSingleVarDeclarator": "error" } } }}¥Description
禁止在同一个变量语句中声明多个变量
¥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
let foo = 0, bar, baz;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
const foo = 0;let bar;let baz;for (let i = 0, x = 1; i < arr.length; i++) {}¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号