'eslint' was used before it was defined
82 fs.writeFileSync(path.join(projectPath, "views", "index.html"), "");
83 fs.writeFileSync(path.join(projectPath, "tsconfig.json"), tsconfig);
84 fs.writeFileSync(path.join(projectPath, ".eslintignore"), eslintIgnore);
85 fs.writeFileSync(path.join(projectPath, "eslint.config.js"), eslint); 86}
87
88const tsconfig = `{
'eslintIgnore' was used before it was defined
81 fs.writeFileSync(path.join(projectPath, "test", "index.test.ts"), "");
82 fs.writeFileSync(path.join(projectPath, "views", "index.html"), "");
83 fs.writeFileSync(path.join(projectPath, "tsconfig.json"), tsconfig);
84 fs.writeFileSync(path.join(projectPath, ".eslintignore"), eslintIgnore); 85 fs.writeFileSync(path.join(projectPath, "eslint.config.js"), eslint);
86}
87
'tsconfig' was used before it was defined
80 fs.writeFileSync(path.join(projectPath, "src", "index.ts"), "");
81 fs.writeFileSync(path.join(projectPath, "test", "index.test.ts"), "");
82 fs.writeFileSync(path.join(projectPath, "views", "index.html"), "");
83 fs.writeFileSync(path.join(projectPath, "tsconfig.json"), tsconfig); 84 fs.writeFileSync(path.join(projectPath, ".eslintignore"), eslintIgnore);
85 fs.writeFileSync(path.join(projectPath, "eslint.config.js"), eslint);
86}
'packageJson' was used before it was defined
58 const projectPath = path.join(process.cwd(), projectName);
59 fs.writeFileSync(
60 path.join(projectPath, "package.json"),
61 packageJson(projectName), 62 );
63 execSync("npm install", { cwd: projectPath, stdio: "inherit" });
64 execSync(
Description
It is recommended to use a variable only after it is defined as it might produce errors at runtime.
In JavaScript, prior to ES6, variable and function declarations are hoisted to the top of a scope, so it's possible to use identifiers before their formal declarations in code. This can be confusing and some believe it is best to always declare variables and functions before using them.
In ES6, block-level bindings (let
and const
) introduce a "temporal dead zone" where a ReferenceError
will be thrown with any attempt to access the variable before its declaration.
Bad Practice
alert(a);
var a = 10;
f();
function f() {}
function g() {
return b;
}
var b = 1;
{
alert(c);
let c = 1;
}
Recommended
var a;
a = 10;
alert(a);
function f() {}
f(1);
var b = 1;
function g() {
return b;
}
{
let c;
c++;
}