after-guard

The blank line after a guard that returns, throws, continues or breaks.

a single-line guard that returns, throws, continues or breaks is followed by a blank line, unless the next statement is an if or a jump (return, throw, break, continue)

A guard here is an if without else whose single body statement is return, throw, continue or break. When the statement after it is anything but another if or a jump, a blank line goes between them: the guard closes one step and the next statement opens another. In the example each throw guard gets a blank line after it, while const slug stays tight against the guard that reads it through guard-join.

Every rule earlier in the order outranks it: short-body, guard-chain, after-multiline, switch-clauses and the join rules. A guard that spans two lines gets the same blank line, reported as after-multiline.

An if whose block holds two statements is not a guard, so nothing is inserted after if (!item) { log("none"); return; }.

Example

Before
function publish(draft: Draft) {
  if (!draft.title) throw new Error("title required");
  const slug = slugify(draft.title);
  if (exists(slug)) throw new Error(`${slug} is taken`);
  save(draft, slug);
  notify(draft.author);
}
After
function publish(draft: Draft) {
  if (!draft.title) throw new Error("title required");

  const slug = slugify(draft.title);
  if (exists(slug)) throw new Error(`${slug} is taken`);

  save(draft, slug);
  notify(draft.author);
}

On this page