2 title: no-case-declarations
10 This rule disallows lexical declarations (`let`, `const`, `function` and `class`)
11 in `case`/`default` clauses. The reason is that the lexical declaration is visible
12 in the entire switch block but it only gets initialized when it is assigned, which
13 will only happen if the case where it is defined is reached.
15 To ensure that the lexical declaration only applies to the current case clause
16 wrap your clauses in blocks.
20 This rule aims to prevent access to uninitialized lexical bindings as well as accessing hoisted functions across case clauses.
22 Examples of **incorrect** code for this rule:
27 /*eslint no-case-declarations: "error"*/
47 Examples of **correct** code for this rule:
52 /*eslint no-case-declarations: "error"*/
55 // Declarations outside switch-statements are valid
59 // The following case clauses are wrapped into blocks using brackets
73 // Declarations using var without brackets are valid due to function-scope hoisting
86 If you depend on fall through behavior and want access to bindings introduced in the case block.