Skip to main content

useSingleCaseStatement

Enforces case clauses have a single statement, emits a quick fix wrapping the statements in a block

Examples

Invalid

switch (foo) {
case true:
case false:
let foo = '';
foo;
}
warning[useSingleCaseStatement]: A switch case should only have a single statement. If you want more, then wrap it in a block.
   useSingleCaseStatement.js:4:9
    
4           let foo = '';
5           foo;
   '

Suggested fix: Wrap the statements in a block
    | @@ -1,6 +1,7 @@
0 0 |   switch (foo) {
1 1 |       case true:
2   | -     case false:
  2 | +     case false: {
3 3 |           let foo = '';
4 4 |           foo;
  5 | +     }
5 6 |   }

Valid

switch (foo) {
case true:
case false: {
let foo = '';
foo;
}
}