Skip to content

feat: zero fmt --write and --check --json envelope#9

Open
mvanhorn wants to merge 1 commit into
vercel-labs:mainfrom
mvanhorn:feat/zero-fmt-write-and-json
Open

feat: zero fmt --write and --check --json envelope#9
mvanhorn wants to merge 1 commit into
vercel-labs:mainfrom
mvanhorn:feat/zero-fmt-write-and-json

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

Summary

zero fmt --write overwrites the source file in place; zero fmt --check --json now emits a structured envelope (today --json is ignored on --check and output stays text-only).

Why this matters

zero fmt --check shipped earlier today and --json envelopes are the contract for every other Zero command. CI pipelines and pre-commit hooks expect the gofmt -l / -w shape: --check for exit-code-on-diff, --write for in-place. With neither, integrations end up shelling diff <(zero fmt file) file (quoting risk on paths) or zero fmt file | tee file (races on large files).

Demo

demo

Changes

  • --write flag overwrites the input file in place. Backward compat preserved: bare zero fmt still prints to stdout.
  • --check --json now emits { schemaVersion, command, mode, sourceFile, ok, unformatted: [...] }. --check text mode unchanged.
  • --write --json mirrors the same shape with written: [...].
  • --check and --write are mutually exclusive.

Testing

  • bin/zero fmt --check examples/hello.0 exits 0
  • bin/zero fmt --check /tmp/messy.0 exits 1 with format differs: ...
  • bin/zero fmt --check --json /tmp/messy.0 emits the envelope with ok: false, exits 1
  • bin/zero fmt --write /tmp/messy.0 rewrites the file, prints formatted: <path>
  • bin/zero fmt --check --write file.0 exits with the mutually-exclusive error
  • bin/zero fmt /tmp/messy.0 (bare) still prints to stdout

Local conformance and native:test exercise pre-existing upstream code paths that already fail on darwin-arm64 (the macho64 emitter is missing LC_UUID; binaries are rejected by dyld). The fmt code path I touched does not go through executable emission, so this PR does not change those failure modes. CI runs in the Vercel sandbox and should be green there.

AI was used for assistance.

Add --write to overwrite the input file in place, and emit a structured
JSON envelope for --check --json (today the --json flag was ignored and
output stayed text-only). --check and --write are mutually exclusive;
bare `zero fmt` keeps current stdout behavior.

JSON shape for both modes:

  {
    "schemaVersion": 1,
    "command": "fmt",
    "mode": "check" | "write",
    "sourceFile": "path",
    "ok": bool,
    "unformatted" | "written": [paths]
  }

Matches the gofmt -l / -w and rustfmt --check / --write split, so
pre-commit hooks and editor save-on-format can call the right verb
without parsing text or shelling diff <(zero fmt file) file.

Help text and docs-site/articles/cli-reference.md updated.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 16, 2026

@mvanhorn is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant