eslint/no-inner-declarations Pedantic ​
What it does ​
Disallow variable or function declarations in nested blocks
Why is this bad? ​
A variable declaration is permitted anywhere a statement can go, even nested deeply inside other blocks. This is often undesirable due to variable hoisting, and moving declarations to the root of the program or function body can increase clarity. Note that block bindings (let, const) are not hoisted and therefore they are not affected by this rule.
Examples ​
Examples of incorrect code for this rule:
if (test) {
function doSomethingElse() {}
}Examples of correct code for this rule:
function doSomethingElse() {}
if (test) {
// your code here
}Configuration ​
This rule accepts a configuration object with the following properties:
blockScopedFunctions ​
default: null
Controls whether function declarations in nested blocks are allowed in strict mode (ES6+ behavior).
config ​
default: "functions"
Determines what type of declarations to check.
How to use ​
To enable this rule in the CLI or using the config file, you can use:
oxlint --deny no-inner-declarations{
"rules": {
"no-inner-declarations": "error"
}
}