Skip to main content

Crate prim_fmt

Crate prim_fmt 

Source
Expand description

The prim formatting engine.

prim is an opinionated, near-zero-config formatter for a repository’s connective tissue — Markdown, JSON/JSONC, YAML, TOML — plus whitespace hygiene on a curated set of un-owned text files.

The engine has two steps:

  1. classify decides whether prim owns a file (by name/extension) and, if so, what FileKind it is. Files prim does not own are left untouched.
  2. [format] applies the canonical formatting for that kind.

[format] applies structured canonicalisation to the parsed formats — JSON/JSONC via dprint-plugin-json, TOML via taplo, YAML via pretty_yaml, Markdown via dprint-plugin-markdown — followed by the format-agnostic whitespace hygiene pass (trailing-whitespace removal, single final line-feed, configured line endings). Orphan files receive hygiene only.

Structs§

Style
The resolved canonical style for one file.

Enums§

FileKind
The kind of file prim recognises. Parsed formats receive structured canonicalisation plus whitespace hygiene; Orphan files (the un-owned text allowlist) only ever receive whitespace hygiene.
FormatError
An error returned by crate::format when a source cannot be formatted.
Indent
Indentation unit. Carried for the per-format parsers (FR-1, #9–12); the whitespace-hygiene pass does not consume it.
LineEnding
The line ending prim emits.

Functions§

classify
Classify path by its final component. Returns None for anything prim does not own (source code, unknown types, binaries) — those are left byte-for-byte unchanged.
format
Format source as the given FileKind under style.