fix(format): keep the trailing zeros of a fraction's terms #287

Merged
abiwab merged 1 commit from fix/format-decimal-denominator into main 2026-11-26 20:20:36 +01:00
Owner

Fixes #286.

Rule 4 (trailing decimal zeros) also trimmed a term of a fraction. The compiler reads neither 1.0/5 nor 1/5.0 as a duration (INVALID_DURATION, or a text quantity), while it reads 1/5, so gram format changed a timer (fuzz format-preserves-meaning … at $.metrics.activeBreakdown[]): ~{1.0/5 min} went from the default 2 min to 0.2 min, ~{1/5.0 min / 500.0 g @&b} to 0.04 min.

  • DECIMAL_WITH_ZEROS no longer matches a number glued to a / (blanks allowed). A ratio's / is never inside one number's range, so ratio terms are still trimmed ({1.50 / 100.0 g @&b} → {1.5 / 100 g @&b}, ~{15.0 min / 500.0 g @&b} → ~{15 min / 500 g @&b}). Cosmetic cost: {1.50/2 g} stays as written.
  • Tests: 4 in packages/format/tests/formatter.test.ts (3 fail without the fix; ~{1/5.0 min}, read as text, is a guard), plus fuzz/regressions/286-fraction-zeros-timer.gram (fails on the old formatter).
  • patch changeset for @gram-lang/format.

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

Independent of #285 (no overlapping lines). Related, out of scope (noted in #286): the parser reads {1.5/2} as 0.75 while kitchen's timer duration rejects ~{1.5/2 min}.

Fixes #286. Rule 4 (trailing decimal zeros) also trimmed a term of a fraction. The compiler reads neither `1.0/5` nor `1/5.0` as a duration (`INVALID_DURATION`, or a text quantity), while it reads `1/5`, so `gram format` changed a timer (fuzz `format-preserves-meaning … at $.metrics.activeBreakdown[]`): `~{1.0/5 min}` went from the default 2 min to 0.2 min, `~{1/5.0 min / 500.0 g @&b}` to 0.04 min. - `DECIMAL_WITH_ZEROS` no longer matches a number glued to a `/` (blanks allowed). A ratio's ` / ` is never inside one number's range, so ratio terms are still trimmed (`{1.50 / 100.0 g @&b}` → `{1.5 / 100 g @&b}`, `~{15.0 min / 500.0 g @&b}` → `~{15 min / 500 g @&b}`). Cosmetic cost: `{1.50/2 g}` stays as written. - Tests: 4 in `packages/format/tests/formatter.test.ts` (3 fail without the fix; `~{1/5.0 min}`, read as text, is a guard), plus `fuzz/regressions/286-fraction-zeros-timer.gram` (fails on the old formatter). - `patch` changeset for `@gram-lang/format`. Checks: 3934 pass / 1 skip / 0 fail, conformance 142/142 and 24/24 with no golden change, typecheck, biome, `deprecations:check`, audit 126, fuzz 50k (seed 3618048934, 0 signature). Independent of #285 (no overlapping lines). Related, out of scope (noted in #286): the parser reads `{1.5/2}` as 0.75 while kitchen's timer duration rejects `~{1.5/2 min}`.
fix(format): keep the trailing zeros of a fraction's terms
All checks were successful
CI / Build & Test (pull_request) Successful in 4m51s
31deb697d5
abiwab merged commit ea23719412 into main 2026-11-26 20:20:36 +01:00
abiwab deleted branch fix/format-decimal-denominator 2026-11-26 20:20:36 +01:00
Sign in to join this conversation.
No description provided.