init-declarations
eslint
No autofix
eslint.config.js
export default [
{
rules: {
"init-declarations": "error",
},
},
];Require or disallow initialization in variable declarations
function foo() {
var bar;
let baz;
}function foo() {
var bar = 1;
let baz = 2;
for (let i = 0; i < 1; i++) {}
}let arr: string[] = ['arr', 'ar'];
const class1 = class NAME {
constructor() {
var name1: string = 'hello';
}
};
namespace myLib {
let numberOfGreetings: number = 2;
}function foo() {
var bar = 1;
let baz = 2;
const qux = 3;
using quux = getSomething();
}
async function foobar() {
await using quux = getSomething();
}function foo() {
var bar;
let baz;
const buzz = 1;
using quux = getSomething();
}
async function foobar() {
await using quux = getSomething();
}for (let i = 0; i < 1; i++) {}Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
init-declarations
eslint
export default [
{
rules: {
"init-declarations": "error",
},
},
];init-declarations
eslint plugin · style
{
"rules": {
"init-declarations": "error"
}
}suspicious/noUnassignedVariables
suspicious · since 2.1.0
{
"linter": {
"rules": {
"suspicious": {
"noUnassignedVariables": "error"
}
}
}
}Require or disallow initialization in variable declarations
Enforce a maximum number of lines of code in a function
Enforce a maximum number of statements allowed in function blocks
Disallow assignments that can lead to race conditions due to usage of await or yield