no-inner-declarations
Added in v0.4.0Configuration
Rule Details
Disallow variable and/or function declarations outside the root of a program,
function body, or class static block body. With the "both" option, this also
applies to var declarations in for, for-in, and for-of headers. It does
not apply to let, const, using, or await using, which are block-scoped.
By default, nested function declarations are allowed only when the code is in
strict mode and languageOptions.ecmaVersion is 2015 or newer. Use the
blockScopedFunctions option to disallow them in those contexts too.
Examples of incorrect code for this rule with the default options in a non-strict script:
Examples of incorrect code for this rule with { blockScopedFunctions: "disallow" }:
Examples of correct code for this rule with the default options:
Examples of incorrect code for this rule with the "both" option:
Examples of correct code for this rule with the "both" option:
Options
"functions"(default): Only disallowsfunctiondeclarations in nested blocks (whenblockScopedFunctionsis"disallow")."both": Disallows bothfunctiondeclarations (whenblockScopedFunctionsis"disallow") andvardeclarations in nested blocks.{ blockScopedFunctions: "allow" | "disallow" }(default"allow"): With"allow", nested function declarations are permitted only in strict code whenlanguageOptions.ecmaVersionis2015or newer. With"disallow", they are always checked.