no-inner-declarations
Configuration
rslint.config.ts
Rule Details
Disallow variable and/or function declarations in nested blocks. Function declarations and, optionally, variable declarations (var) should only appear at the root level of a program or the body of a function. This does not apply to let or const, which are block-scoped by design.
By default, function declarations in blocks are allowed because they are valid in ES2015+ strict mode (block-scoped). Use the blockScopedFunctions option to disallow them.
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"): Controls whether function declarations inside blocks are reported. When"allow"(default), block-scoped function declarations are permitted as they are valid in ES2015+ strict mode.