Lint Rules

useSingleCaseStatement (since v0.7.0)

This rule is recommended by Rome.

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;
}
correctness/useSingleCaseStatement.js:4:9 lint/correctness/useSingleCaseStatement  FIXABLE  ━━━━━━━━━━

   A switch case should only have a single statement. If you want more, then wrap it in a block.
  
    2 │     case true:
    3 │     case false:
  > 4 │         let foo = '';
           ^^^^^^^^^^^^^
  > 5 │         foo;
           ^^^^
    6 │ }
    7 │ 
  
   Suggested fix: Wrap the statements in a block
  
    1 1  switch (foo) {
    2 2      case true:
    3  - ····case·false:
      3+ ····case·false:·{
    4 4          let foo = '';
    5 5          foo;
      6+ ····}
    6 7  }
    7 8  
  

Valid

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