Skip to main content

js/useSingleCaseStatement

MISSING DOCUMENTATION

Examples

Invalid

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

 file.ts:3:1 lint/js/useSingleCaseStatement  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━

  A switch case should only have a single statement. If you want more,
    then wrap it in a block.

    1switch (foo) {
    2  case true:
  > 3  case false:
       ^^^^^^^^^^^
  > 4    let foo = '';
  > 5    foo;
     ^^^^^^^^
    6}

  Safe fix

    1  - case·false:
      1+ case·false:·{
    2 2  let·foo·=·"";
    3  - foo;
      3+ foo;
      4+ }

Valid

switch (foo) {
	case true:
	case false:
		'yes';
}
switch (foo) {
	case true: {
		// empty
	}
}
switch (foo) {
	case true:
}