Stanza

Braces and Lint Config

The lint config and flags that decide whether the braces rule runs.

The braces rule removes the braces around a single statement control flow body. It keeps them where removing them would change parsing (a dangling else, a declaration as the body, a statement without a trailing ; that the next line could continue) and where the block holds a comment. The rule page lists every case. A body that fits goes onto its header line, and every other line break is left to the formatter.

Lint Config

A repo that enforces braces through its linter keeps them, so Stanza does not fight the lint rule. Without a flag, Stanza walks up from each file's directory and reads the lint config it finds:

  • flat ESLint (eslint.config.*) and legacy ESLint (.eslintrc*, eslintConfig in package.json): the curly rule;
  • Biome (biome.json, biome.jsonc): useBlockStatements, the style group turned on, or all: true;
  • Oxlint (.oxlintrc.json, .oxlintrc.jsonc, oxlint.config.ts): curly or eslint/curly, categories.style, and overrides.

files, ignores and includes scoping applies per file, so a config that enforces braces only under src/ leaves the other files to the rule. Any config that enforces braces, or that Stanza cannot read, keeps braces.

When a config is unknown and no config turns braces on, Stanza prints one line on stderr per run:

stanza: cannot tell whether <files> enforces braces, so braces stay; pass --braces or --no-braces to settle it

Under --fix --stdin --json stderr carries the findings, so the notice is not printed there.

Flags

--braces turns the rule on even where lint config turns it off or Stanza cannot read the config. --no-braces turns it off and keeps the blank line rules. With either flag the config is not read and no notice prints. Passing both is a usage error. stanza hook takes --braces, --no-braces and --hunks in its command. See CLI.

Example

The biome.json beside this file turns useBlockStatements on, so the braces around continue stay while the blank line rules still run.

function keep(items: Item[]) {
  for (const item of items) {
    if (!item) {
      continue;
    }
  }

  return items;
}

On this page