requireVarDeclFirst

Requires var declaration to be on the top of an enclosing scope

Types: Boolean

Values:

  • true specifies that var declarations must occur the top of a function scope.

Example

"requireVarDeclFirst": true
Valid for mode true
var x = 1,
    y = 2;
'use strict;'
var x = 1,
    y = 2;
var x = 1;
var y = 2;
var x = 1;
// comments
var y = 2;
var x = 1;
// comments
// comments 2
var y = 2;
const a = 1;
const b = 2;
var x = 1;
function y() {var z;};
var x = 1;
var y = function () {var z;};
var w = 1;
function x() {
 var y;
// comments
// comments 2
 var z;
};
var w = 1;
function x() {
 "use strict";
 var y;
};
var x = 1;
var y;
for (y = 0; y < 10; y++) {};
Invalid
var x;
x = 1;
var y = 2;
var w = 1;
function x() {var y;};
var z = 2;
var w = 1;
function x() {
 var y;
 y = 2;
 var z;
};
var a;
for(var count=0;count < 10;count++){}
var x;
for(var count=0;count < 10;count++){
 var y;
}
Rule source
Test source