newline-before-break

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

Requires a blank line before a break that follows another statement.

Checks labeled and unlabeled breaks in blocks. First statements, unbraced breaks, and switch-case lists are exempt. Blank lines above comments count.

Invalid

example.dartdart
void loops(bool condition) {
  while (condition) {
    print('before');
    break;
  }
  outer: for (var i = 0; i < 3; i++) {
    while (condition) {
      print('nested');
      break outer;
    }
  }
}

void commented(bool condition) {
  while (condition) {
    print('before');
    // No separating blank line.
    break;
  }
}
Add a blank line before this `break` statement.
3 print('before');
4 break;
Add a blank line before this `break` statement.
8 print('nested');
9 break outer;
Add a blank line before this `break` statement.
17 // No separating blank line.
18 break;

Valid

example.dartdart
void loops(bool condition) {
  while (condition) {
    break;
  }
  while (condition) {
    print('before');

    break;
  }
  outer: for (var i = 0; i < 3; i++) {
    while (condition) {
      break outer;
    }
  }
  while (condition) {
    if (condition) break;
  }
}

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

void commented(bool condition) {
  while (condition) {
    print('before');

    // Stop this loop.
    break;
  }
}

Configure newline-before-break

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

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

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

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