newline-before-case

Group
Style
Path
lint/style/newline-before-case
Default
Off, opt in
Origin
Falcon
Rule
274 of 512

Requires a blank line between successive switch statement case clauses.

The first clause is exempt, and grouped labels need no blank line between them. Nested switches are checked independently, including default clauses. Blank lines above attached comments count.

Invalid

example.dartdart
void select(int value) {
  switch (value) {
    case 0:
      print(0);
      break;
    case 1:
      switch (value) {
        case 1:
          break;
        default:
          break;
      }
      break;
    default:
      break;
  }
}

void commented(int value) {
  switch (value) {
    case 0:
      break;
    // No separating blank line.
    default:
      break;
  }
}
Add a blank line before this `case` clause.
5 break;
6 case 1:
Add a blank line before this `case` clause.
9 break;
10 default:
Add a blank line before this `case` clause.
13 break;
14 default:
Add a blank line before this `case` clause.
23 // No separating blank line.
24 default:

Valid

example.dartdart
void select(int value) {
  switch (value) {
    case 0:
      print(0);
      break;

    case 1:
      switch (value) {
        case 1:
          break;

        default:
          break;
      }
      break;

    default:
      break;
  }
}

void single(int value) {
  switch (value) {
    default:
      break;
  }
}

void grouped(int value) {
  switch (value) {
    case 0:
    case 1:
      print(value);
      break;

    // These labels share a body.
    case 2:
    case 3:
      break;

    /* The blank line precedes this comment. */
    default:
      break;
  }
}

Configure newline-before-case

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "newline-before-case": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/style/newline-before-case: <reason>