Rule: one-variable-per-declaration

Disallows multiple variable definitions in the same declaration statement.

Config

One argument may be optionally provided:

  • ignore-for-loop allows multiple variable definitions in a for loop declaration.
Config examples
"one-variable-per-declaration": true
"one-variable-per-declaration": [true, "ignore-for-loop"]
Schema
{
  "type": "array",
  "items": {
    "type": "string",
    "enum": [
      "ignore-for-loop"
    ]
  },
  "minLength": 0,
  "maxLength": 1
}

Code examples:

Disallows multiple variable definitions in the same declaration statement.
"rules": { "one-variable-per-declaration": true }
Passes
const foo = 1;
const bar = '2';
Fails
const foo = 1, bar = '2';
Disallows multiple variable definitions in the same declaration statement but allows them in for-loops.
"rules": { "one-variable-per-declaration": [true, "ignore-for-loop"] }
Passes
for (let i = 0, j = 10; i < 10; i++) {
    doSomething(j, i);
}