curly_braces_in_flow_control_structures

Group: style

Maturity: stable

Dart SDK: >= 2.0.0 • (Linter v0.1.57)

View the Project on GitHub dart-lang/linter

DO use curly braces for all flow control structures.

Doing so avoids the dangling else problem.

GOOD:

if (isWeekDay) {
  print('Bike to work!');
} else {
  print('Go dancing or read a book!');
}

There is one exception to this: an if statement with no else clause where the entire if statement and the then body all fit in one line. In that case, you may leave off the braces if you prefer:

GOOD:

if (arg == null) return defaultValue;

If the body wraps to the next line, though, use braces:

GOOD:

if (overflowChars != other.overflowChars) {
  return overflowChars < other.overflowChars;
}

BAD:

if (overflowChars != other.overflowChars)
  return overflowChars < other.overflowChars;