no-use-before-define
eslint
No autofix
eslint.config.js
export default [
{
rules: {
"no-use-before-define": "error",
},
},
];Disallow the use of variables before they are defined
alert(a);
var a = 10;
f();
function f() {}
function g() {
return b;
}
var b = 1;
{
alert(c);
let c = 1;
}
{
class C extends C {}
}
{
class C {
static x = "foo";
[C.x]() {}
}
}
{
const C = class {
static x = C;
}
}
// …var a;
a = 10;
alert(a);
function f() {}
f(1);
var b = 1;
function g() {
return b;
}
{
let c;
c++;
}
{
class C {
static x = C;
}
}
{
const C = class C {
static x = C;
}
}
{
const C = class {
x = C;
// …Examples from the ESLint documentation.
no-use-before-define
eslint
export default [
{
rules: {
"no-use-before-define": "error",
},
},
];no-use-before-define
eslint plugin · restriction
{
"rules": {
"no-use-before-define": "error"
}
}correctness/noInvalidUseBeforeDeclaration
correctness · since 1.5.0
{
"linter": {
"rules": {
"correctness": {
"noInvalidUseBeforeDeclaration": "error"
}
}
}
}Disallow the use of variables before they are defined
Disallow unnecessary constructors
Require using arrow functions for callbacks
Disallow ternary operators when simpler alternatives exist
Enforce the use of the radix argument when using parseInt()