fix(format): format a fenced block the parser reads as a step like the body #285

Merged
abiwab merged 1 commit from fix/format-fenced-block-not-frontmatter into main 2026-11-26 20:20:26 +01:00
Owner

Fixes #284.

The formatter's splitFrontmatter took any ----fenced block as frontmatter, while the parser's Frontmatter rule accepts key: value lines only and reads anything else as a step. Rule 10 then stripped a trailing blank inside a block comment the parser keeps verbatim (fuzz format-preserves-meaning), and rules 1-8 skipped the block's elements.

  • New frontmatterOf(): the textual split is kept only when the parser finds no span (element, comment, action, title) inside the fenced block; otherwise the whole file is body. A file that does not parse keeps the textual split (whitespace rules only). One extra parse, only when a fenced block opens the file.
  • Tests: 2 in packages/format/tests/formatter.test.ts (both fail without the fix), plus the fuzz input in fuzz/regressions/284-fenced-block-comment.gram.
  • patch changeset for @gram-lang/format.

Checks: 3932 pass / 1 skip / 0 fail, conformance 142/142 and 24/24 with no golden change, typecheck, biome, deprecations:check, audit 126, fuzz 50k (seed 2726604960, 0 signature).

Fixes #284. The formatter's `splitFrontmatter` took any `---`-fenced block as frontmatter, while the parser's `Frontmatter` rule accepts `key: value` lines only and reads anything else as a step. Rule 10 then stripped a trailing blank inside a block comment the parser keeps verbatim (fuzz `format-preserves-meaning`), and rules 1-8 skipped the block's elements. - New `frontmatterOf()`: the textual split is kept only when the parser finds no span (element, comment, action, title) inside the fenced block; otherwise the whole file is body. A file that does not parse keeps the textual split (whitespace rules only). One extra parse, only when a fenced block opens the file. - Tests: 2 in `packages/format/tests/formatter.test.ts` (both fail without the fix), plus the fuzz input in `fuzz/regressions/284-fenced-block-comment.gram`. - `patch` changeset for `@gram-lang/format`. Checks: 3932 pass / 1 skip / 0 fail, conformance 142/142 and 24/24 with no golden change, typecheck, biome, `deprecations:check`, audit 126, fuzz 50k (seed 2726604960, 0 signature).
fix(format): format a fenced block the parser reads as a step like the body
All checks were successful
CI / Build & Test (pull_request) Successful in 5m1s
466d139bf7
abiwab merged commit e5cf528f99 into main 2026-11-26 20:20:26 +01:00
abiwab deleted branch fix/format-fenced-block-not-frontmatter 2026-11-26 20:20:27 +01:00
Sign in to join this conversation.
No description provided.