Skip to content

Add oxfmt formatter with auto-format PR workflow#4

Merged
darylcecile merged 2 commits into
mainfrom
darylcecile/add-oxfmt-formatter
May 31, 2026
Merged

Add oxfmt formatter with auto-format PR workflow#4
darylcecile merged 2 commits into
mainfrom
darylcecile/add-oxfmt-formatter

Conversation

@darylcecile

Copy link
Copy Markdown
Owner

Now that the project is open source, contributor PRs have been silently reformatting hand-written code (see #2, where the bulk of the diff was collapsed object literals being re-expanded to multi-line and reordered imports). This change locks in the existing style with a fast formatter and makes contributors' lives easier by running it for them in CI.

Approach

  • .oxfmtrc.jsonoxfmt@0.52 config tuned to the existing codebase: 2-space indent, double quotes, semicolons, trailing commas, printWidth: 100. Two non-default options matter:
    • objectWrap: "collapse" — defeats Prettier-style magic-trailing-comma expansion, which was the dominant noise in feat(vm): add maxSteps execution budget #2.
    • sortImports: true — keeps import statement order canonical.
  • package.json — adds bun run format and bun run format:check; adds oxfmt as a devDependency.
  • AGENTS.md — documents the new commands and adds a "don't hand-reformat" rule for agents.
  • .github/workflows/format-pr.yml — runs bun run format on every PR and pushes the result back as a github-actions[bot] commit, so contributors never need to think about it.

How the rules were validated

I diffed the base and head of #2, ran our formatter on both sides, then compared. Drop in noise per file:

File raw diff lines remaining after format
src/boundary.ts 334 2
test/interpreter-evaluator.test.ts 507 4
src/vm.ts 715 208 (real PR content)
test/vm.test.ts 358 80 (real PR content)

The remaining diffs are genuine semantic changes, not formatting.

Things to know before merging

  • One-time normalization needed. The codebase was never formatter-managed. bun run format:check on main will fail today (28 files need touching). Recommend running bun run format on main as a single dedicated commit before this CI starts gating PRs, so future PRs only show real changes.
  • Fork PRs are not auto-formatted. The workflow is gated on head.repo == github.repository. Fork PRs only get a read-only GITHUB_TOKEN, so the push step would fail with 403. The alternatives (pull_request_target with PR-head checkout, or a PAT) are known pwn-request vectors and I did not want to opt into them silently. Fork contributors run bun run format locally. Happy to layer a format:check job on top so they get a failing status — say the word.
  • No infinite loop risk. Pushes by GITHUB_TOKEN do not trigger workflow runs (docs).
  • One small style drift oxfmt can't enforce today: sorting named specifiers within an import statement (e.g. { VMError, VMErrorCode, createCapability } vs { createCapability, VMError, VMErrorCode }). There's no oxfmt option for it; would need an ESLint rule layered on top.

darylcecile and others added 2 commits May 31, 2026 14:30
Set up oxfmt 0.52 as the project's formatter so contributor PRs cannot
silently drift from the existing code style. Rules were tuned against
PR #2, which contained large amounts of formatting noise (collapsed
object literals re-expanded to multi-line, reordered imports) on top of
real changes.

- .oxfmtrc.json: 2-space, double quotes, semicolons, trailing commas,
  printWidth 100, objectWrap=collapse (defeats magic-trailing-comma
  expansion), sortImports=true (canonical import statement order).
- package.json: format and format:check scripts; oxfmt devDependency.
- AGENTS.md: documents the format commands and the no-hand-reformat rule.
- .github/workflows/format-pr.yml: runs bun run format on every same-repo
  PR and pushes the result back as a github-actions[bot] commit. Gated
  on head.repo == github.repository because fork PRs only get a
  read-only GITHUB_TOKEN; fork contributors run format locally.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@darylcecile darylcecile merged commit 9382ea6 into main May 31, 2026
1 check passed
@darylcecile darylcecile deleted the darylcecile/add-oxfmt-formatter branch May 31, 2026 13:36
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