Skip to content

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

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

mvanhorn wants to merge 2 commits 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.

@vercel

vercel Bot commented May 16, 2026

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

gke0op added a commit to gke0op/zero that referenced this pull request May 18, 2026
Adds --write flag and --json envelope support to zero fmt, matching
the contract of every other Zero command.

New features:
- zero fmt --write <file> overwrites the file in place
- zero fmt --check --json emits { schemaVersion, command, mode, sourceFile, ok, unformatted }
- zero fmt --write --json emits { schemaVersion, command, mode, sourceFile, ok, written }
- --check and --write are mutually exclusive (error in both text and json modes)
- Bare zero fmt still prints to stdout (backward compat)

Text mode for --check is unchanged (fmt ok / format differs).

Closes vercel-labs#9
gke0op added a commit to gke0op/zero that referenced this pull request May 18, 2026
Adds --write flag and --json envelope support to zero fmt, matching
the contract of every other Zero command.

New features:
- zero fmt --write <file> overwrites the file in place
- zero fmt --check --json emits { schemaVersion, command, mode, sourceFile, ok, unformatted }
- zero fmt --write --json emits { schemaVersion, command, mode, sourceFile, ok, written }
- --check and --write are mutually exclusive (error in both text and json modes)
- Bare zero fmt still prints to stdout (backward compat)

Text mode for --check is unchanged (fmt ok / format differs).

Closes vercel-labs#9
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.
@mvanhorn
mvanhorn force-pushed the feat/zero-fmt-write-and-json branch from 7667c32 to fe58018 Compare August 13, 2026 16:35
Comment thread native/zero-c/src/main.c Resolved
fopen(..., "wb") truncated the source before writing, so an interrupted
or short write lost the original file, and it wrote straight through
symlinks. Use z_write_file, which writes a temp file, renames it, and
refuses unsafe output paths.
@vercel-internal-security-reviewer

Copy link
Copy Markdown

Security review details

This branch has not been deployed

No deployments
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