short-body

Why a body of two or three compact statements has no blank lines.

a block of two or three single-line statements has no blank lines, whether it is a function body, a nested block or a switch clause body. A braceless if or loop whose header and body each sit on one line counts as single-line here, because the formatter puts it on one line

Applies to any statement list of two or three statements where every statement is compact: a function body, an arrow body, a method, a nested if or loop block, a static block, or the body of a case. Not to the list of clauses in a switch. Every gap in the list loses its blank lines.

Compact means on one line, or a braceless if without else, for or while whose header is on one line and whose body is compact. Comments are not statements, so a comment does not stop a body from being short. Four statements is not short.

Nothing outranks it. It is the first rule tried, so it wins over after-multiline (a braceless two line guard in a short body gets no blank line after it), over after-guard (in the example if (event.silent) return; is followed directly by the next statement), over the join rules and over let-step.

Example

Before
function record(event: Event, log: Event[]) {
  if (event.silent) return;

  log.push(event);

  flush(log);
}
After
function record(event: Event, log: Event[]) {
  if (event.silent) return;
  log.push(event);
  flush(log);
}

On this page