prim-fmt
The formatting engine behind prim — an opinionated, near-zero-config formatter for a repository's connective tissue (Markdown, JSON/JSONC, YAML, TOML) plus whitespace hygiene.
This crate is the pure library: strings in, strings out, no CLI or terminal
dependencies, so other tools can embed it. The prim binary is published
separately as prim-cli.
Status: early.
classify+formatapply the whitespace-hygiene pass to the parsed formats and the orphan allowlist; structured per-format passes land in later milestones. See the specification.
Usage
use Path;
// Classify a file by name, then format its contents for that kind.
if let Some = classify
Correctness fixtures
tests/correctness/fixtures/<format>/*.txt drive the correctness harness
(FR-6.1 idempotency, FR-6.2 semantic preservation, plus format-equality). Each
file has -- input -- and -- expected -- sections, plus an optional
-- config -- section overriding the default Style. The directory name
selects the FileKind (json, jsonc, toml, yaml, markdown, hygiene).
To add a fixture: create the file with your -- input -- and an empty
-- expected --, then run:
PRIM_SPEC_UPDATE=1
Review the generated diff before committing — this is the step where a formatter bug would show up as unexpected output.
Benchmarks
benches/format.rs times format() per file kind (JSON, TOML, YAML, Markdown)
across small/medium/large synthetic inputs generated at bench time (no vendored
corpus — deterministic and reproducible). Run:
This is not part of just check or CI — it's slow and its numbers are
machine-dependent, so it's for local regression-hunting, not a gate. HTML
reports land in target/criterion/report/index.html. There is currently no
tracked performance baseline; treat a run before and after your change as the
comparison, not an absolute number.
License
MIT © driftsys