Skip to content
Beskid Platform specification

Beskid

Jump to a Beskid service

Beskid

Jump to a Beskid service

Formatter verification and traceability

Platform spec article

Formatter verification and traceability

Spec standingStandard

Owner
Piotr Mikstacki
Submitter
Piotr Mikstacki

This article enumerates the concrete artifacts that demonstrate formatter conformance — test paths, CI commands, code anchors — so that anyone modifying beskid_analysis::format or beskid_cli::commands::format can verify they have not regressed the parent hub contract.

It complements the design model which explains how the formatter is built; this article focuses on how it is verified.

  • Formatter — feature hub with the normative contract.
  • Design modelEmit/EmitCtx/Emitter architecture.
  • compiler/crates/beskid_analysis/docs/formatter.md — implementation-side overview that mirrors the hub.
ConcernFile or moduleWhat it proves
Public formatter entry pointcompiler/crates/beskid_analysis/src/format/mod.rsformat_program and emit_error_semantic_diagnostic are the only re-exported names; consumers must not depend on per-construct emitters.
Layout policycompiler/crates/beskid_analysis/src/format/policy.rsBlank-line policy, between-members policy, between-block-items policy live in one file (no scatter).
Context helperscompiler/crates/beskid_analysis/src/format/emit.rs::EmitCtxopen_brace/close_brace/write_indent are the only sanctioned indent and brace primitives.
Per-construct projectioncompiler/crates/beskid_analysis/src/format/items/, expressions_emit.rs, statements_emit.rs, types_emit.rsEach AST node has a focused Emit impl; mod.rs is exports-only.
CLI surfacecompiler/crates/beskid_cli/src/commands/format.rsbeskid format / fmt with --write, --check, --output, single-file stdout default.

The following commands must pass before any change to the formatter is merged:

  1. Crate compile + unit tests:
    Terminal window
    cd compiler && cargo test -p beskid_analysis format::
  2. CLI compile + filter-named tests:
    Terminal window
    cd compiler && cargo test -p beskid_cli format
    The filter currently matches no test names, so this acts as a compile gate; future format-specific CLI tests must match this filter so they run automatically.
  3. Strict platform-spec verification (covers this hub + the parent feature):
    Terminal window
    cd site/website && bun run verify:trudoc -- --preset ci

The formatter contract requires:

format_program(parse(format_program(parse(s)))) == format_program(parse(s))

This must be enforced by at least one test in beskid_analysis that feeds a curated representative source corpus (functions, types, attributes, tests, control flow, generics) and asserts the equality after two formatter passes.

Any change to format/policy.rs or format/emit.rs::EmitCtx must be accompanied by a test run that demonstrates the idempotency property still holds after fixtures are regenerated.

  • PR drift check — the Beskid CI pipeline must include a beskid format --check step against the workspace source tree. A drift hit must fail the PR.
  • Spec verification — the verify:trudoc -- --preset ci step covers PSC003 (Standard feature hubs require ## Decisions) and PSC006 (ADR pages require ## Context / ## Decision). This hub satisfies both via the embedded Decisions section and the ADR bundle under adr/.
OwnerWhat changes hereMirror
Formatter feature hub (tooling/formatter/index.mdx)Normative contract, layout policy, ADR list.compiler/crates/beskid_analysis/docs/formatter.md — implementation overview kept in sync.
policy.rsBlank-line / between-member / between-block-items policy.Update Layout policy section on the hub.
EmitCtx helpersIndent unit, brace primitives.Update Layout policy section on the hub.
beskid format CLI flagsFlag set, file-scan ignore list.Update Inputs and outputs section on the hub.

Discrepancies between this article and the implementation are defects: report them as PRs that update both files in the same change set.