disallowMultipleVarDecl

Disallows multiple var declaration (except for-loop).

Types: Boolean or Object

Values:

  • true disallows multiple variable declarations except within a for loop
  • Object:
    • 'strict' disallows all multiple variable declarations
    • 'allExcept' array of exceptions:
      • 'undefined' allows declarations where all variables are not defined
      • 'require' allows declarations where all variables are importing external modules with require

Example

"disallowMultipleVarDecl": true
Valid for true
var x = 1;
var y = 2;

for (var i = 0, j = arr.length; i < j; i++) {}
Valid for { strict: true }
var x = 1;
var y = 2;
Valid for { allExcept: ['undefined'] }
var a, b;
var x = 1;
var y = 2;

for (var i = 0, j = arr.length; i < j; i++) {}
Valid for { allExcept: ['require'] }
var a = require('a'),
    b = require('b');

var x = 1;
var y = 2;

for (var i = 0, j = arr.length; i < j; i++) {}
Invalid
var x = 1,
    y = 2;

var x, y = 2, z;
Rule source
Test source