chore: replace prettier with oxfmt and enforce format:check in CI - #277
Open
LukeSheard wants to merge 2 commits into
Open
chore: replace prettier with oxfmt and enforce format:check in CI#277LukeSheard wants to merge 2 commits into
LukeSheard wants to merge 2 commits into
Conversation
Adopt oxfmt (the oxc formatter) for JavaScript and TypeScript, and gate pull requests on a formatting check so they can't carry whitespace-only churn. - Add `oxfmt` and `.oxfmtrc.json`. `printWidth` is pinned to 80 to match the repo's existing Prettier-formatted style; every other option is left at oxfmt's Prettier-compatible default. - `ignorePatterns` keeps oxfmt off build output and off the file types Prettier still owns (JSON, Markdown, YAML, CSS). - Add `pnpm run format` and `pnpm run format:check` at the root. - Add a `Format` workflow that runs `pnpm run format:check` on pull requests and on pushes to `main`. - Switch the lint-staged JS/TS entry from Prettier to oxfmt, and widen its glob to cover `examples/` and the remaining JS/TS extensions. Prettier keeps handling JSON and Markdown. - Reformat the 68 JS/TS files that were not already formatted. Co-Authored-By: LukePS <9877376+LukeSheard@users.noreply.github.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Comment on lines
+15
to
+34
| name: Check formatting | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout Repo | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - uses: pnpm/action-setup@v4 | ||
| with: | ||
| run_install: false | ||
|
|
||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: "24.16.0" | ||
| cache: "pnpm" | ||
|
|
||
| - run: pnpm install | ||
| shell: bash | ||
|
|
||
| - name: Check formatting | ||
| run: pnpm run format:check |
oxfmt already handles JSON, Markdown, YAML and CSS, so there is no reason to keep a second formatter around. - Remove the `prettier` devDependency. The only remaining `prettier` in the lockfile is 2.8.8, vendored inside `@changesets/write`. - Drop the per-language `ignorePatterns` from `.oxfmtrc.json` so oxfmt covers every file type it understands. Coverage goes from 216 to 289 files, and none of the newly covered files needed reformatting. - Set `sortPackageJson: false`. It defaults to true and reorders `package.json` keys and dependency lists, which is a source transformation rather than formatting, and would make the changesets release PR fail the format check whenever it rewrote a manifest. - Collapse lint-staged to a single `*` group running oxfmt. oxfmt skips file types it does not understand (binaries, SVG), so the glob does not need to enumerate extensions, and the single group removes the concurrent `git add` race the two groups had. Co-Authored-By: LukePS <9877376+LukeSheard@users.noreply.github.com>
| ], | ||
| "*.{json,md}": [ | ||
| "prettier --write", | ||
| "*": [ |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The repo has no formatting gate. Prettier is wired into a
pre-commithook, but nothing verifies formatting in CI, so files drift out of shape and PRs end up carrying whitespace-only churn alongside real changes. 68 committed JS/TS files were already not formatted.Change
Replace Prettier with oxfmt (the oxc formatter) as the repo's only formatter, and fail CI when anything isn't formatted.
.oxfmtrc.json— oxfmt covers every file type it understands: JS, TS, JSON, Markdown, YAML, CSS.ignorePatternsonly excludes build output (dist,.next,.turbo, …); oxfmt already skips lockfiles, dot-directories and file types it doesn't handle (binaries, SVG). 289 files are covered.prettierdevDependency is gone, along with its lint-staged entry and the CONTRIBUTING reference. The onlyprettierleft in the lockfile is 2.8.8, vendored inside@changesets/write.pnpm run formatandpnpm run format:checkat the root.Formatworkflow runspnpm run format:checkon every pull request and on pushes tomain. It's a separate job fromPublishso formatting feedback is fast and a format failure can't wedge a release.*group runningoxfmt. Since oxfmt no-ops on unsupported files, the glob doesn't need to enumerate extensions, and one group removes the concurrentgit addrace the two groups had.Two config choices worth a look
printWidth: 80rather than oxfmt's default of100. 80 matches the repo's existing Prettier-formatted style; 100 would have reflowed ~123 files (−1200 net lines) instead of 68. Easy to flip later as its own PR.sortPackageJson: false— this defaults totrueand reorderspackage.jsonkeys and sorts dependency lists. That's a source transformation rather than formatting, it's not something Prettier ever did, and it would make the changesets release PR fail the format check whenever it rewrote a manifest. Left off deliberately.Notes on the diff
The bulk of this PR is the mechanical JS/TS reformat. The reviewable part is
.oxfmtrc.json,package.json,.github/workflows/format.yml, andCONTRIBUTING.md.Most reformatted hunks are cases where oxfmt follows Prettier 3.6+'s ternary and type-parameter formatting while the repo is on Prettier 3.5.3 — plus a handful of lines that simply exceeded 80 columns and were never formatted at all. Dropping Prettier cost zero extra churn: every JSON, Markdown, YAML and CSS file in the repo already matched oxfmt's output.
Verification
pnpm run format:check— clean, 289 filesgit diff --check— cleanpnpm run build(typecheck + build, 8 tasks) — passingpackages/vercel-sandbox-mocktests — 195 passed, 86 skipped.ts,.json,.mdand.yaml(all formatted) and a binary.ico(untouched)The
@vercel/sandboxandsandboxtest suites hit the real API and weren't run locally.