Skip to content

Latest commit

 

History

History
86 lines (57 loc) · 1.53 KB

newline-between-switch-case.md

File metadata and controls

86 lines (57 loc) · 1.53 KB

newline-between-switch-case

Require newlines between switch cases.

Options

The rule takes a first option of either "always" or "never" as to whether there should be a newline between cases. It also takes an object with the following options:

  • fallthrough - "always" or "never" - whether or not to have newlines between cases that fallthrough to each other.

Rule Details

The following patterns are considered problems:

/*eslint switch-case/newline-between-switch-case: ["error", "always"]*/

switch (a) {
  case 0:
  case 1:
    doSomething();
    break;
  case 2:
    doSomething();
    break;
}

The following patterns are not considered warnings:

/*eslint switch-case: "error"*/

/*eslint switch-case/newline-between-switch-case: ["error", "always"]*/

switch (a) {
  case 0:

  case 1:
    doSomething();
    break;

  case 2:
    doSomething();
    break;
}

fallthrough option

The following patterns are considered problems:

/*eslint switch-case/newline-between-switch-case: ["error", "always", { "fallthrough": "never"}]*/

switch (a) {
  case 0:

  case 1:
    doSomething();
    break;
}

The following patterns are not considered warnings:

/*eslint switch-case: "error"*/

/*eslint switch-case/newline-between-switch-case: ["error", "always", { "fallthrough": "never"}]*/

switch (a) {
  case 0:
  case 1:
    doSomething();
    break;
}

When Not To Use It

If you don't want to enforce newlines between switch cases.