vars-on-top
eslint
No autofix
eslint.config.js
export default [
{
rules: {
"vars-on-top": "error",
},
},
];Require var declarations be placed at the top of their containing scope
// Variable declaration in a nested block, and a variable declaration after other statements:
function doSomething() {
if (true) {
var first = true;
}
var second;
}
// Variable declaration in for initializer:
function doSomethingElse() {
for (var i=0; i<10; i++) {}
}// Variable declaration after other statements:
f();
var a;// Variables in class static blocks should be at the top of the static blocks.
class C {
// Variable declaration in a nested block:
static {
if (something) {
var a = true;
}
}
// Variable declaration after other statements:
static {
f();
var a;
}
}function doSomething() {
var first;
var second; //multiple declarations are allowed at the top
if (true) {
first = true;
}
}
function doSomethingElse() {
var i;
for (i=0; i<10; i++) {}
}var a;
f();class C {
static {
var a;
if (something) {
a = true;
}
}
static {
var a;
f();
}
}Examples from the ESLint documentation.
vars-on-top
eslint
export default [
{
rules: {
"vars-on-top": "error",
},
},
];vars-on-top
eslint plugin · style
{
"rules": {
"vars-on-top": "error"
}
}style/useVarsOnTop
style · since 2.4.12
{
"linter": {
"rules": {
"style": {
"useVarsOnTop": "error"
}
}
}
}Require grouped accessor pairs in object literals and classes
Disallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead
Disallow returning values from Promise executor functions
Require for-in loops to include an if statement
Require braces around arrow function bodies