Aller au contenu

useSingleVarDeclarator

Ce contenu n’est pas encore disponible dans votre langue.

Diagnostic Category: lint/style/useSingleVarDeclarator

Since: v1.0.0

Sources:

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.

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

const foo = 0;
let bar;
let baz;
for (let i = 0, x = 1; i < arr.length; i++) {}