Commit 6f8ff69
authored
fix(lefthook): exclude package.json from oxlint/oxfmt (CopilotKit#5059)
## Summary
Removes `json`, `jsonc`, `json5` from the `lint-fix` pre-commit hook's
glob in `lefthook.yml`. These extensions caused `oxfmt --write` to
rewrite `package.json` files into invalid JSON5 syntax, breaking every
commit that touched a `package.json` until the hook was bypassed.
## The bug
When `package.json` is staged and the `lint-fix` hook runs `oxlint
--fix` + `oxfmt --write` over `{staged_files}`, oxfmt rewrites the file
into:
- 4-space indent (instead of 2)
- Trailing commas after the last key in every object
- Compact single-line objects (e.g. `"publishConfig": {"access":
"public"}`)
The result is **invalid strict JSON**. `pnpm install` then fails with:
```
ERR_PNPM_JSON_PARSE Unexpected token } in JSON at line 8 column 5
```
This blocks the commit because lefthook re-stages the mangled file
(`stage_fixed: true`), and any downstream tooling that calls `pnpm
install` (sync-lockfile, CI, etc.) rejects it.
### Reproduction
With the buggy glob in place:
1. Edit any `package.json` (e.g. add a key)
2. `git add packages/<pkg>/package.json`
3. `lefthook run pre-commit --command lint-fix`
4. oxfmt logs `1 file reformatted`
5. `node -e
"JSON.parse(require('fs').readFileSync('packages/<pkg>/package.json','utf8'))"`
throws `SyntaxError: Expected double-quoted property name in JSON`
PRs CopilotKit#5054 and CopilotKit#5055 both shipped with `LEFTHOOK_EXCLUDE=lint-fix` to
work around this.
## The fix
Drop `json,jsonc,json5` from the `lint-fix` glob. JSON formatting in
this repo is owned by `pnpm` (writes strict 2-space JSON during lockfile
sync) and manual editing — neither produces JSON5. oxfmt 0.36 exposes no
per-file knobs (`printWidth`, `proseWrap`, `ignorePatterns` only) to
keep `package.json` valid output, so excluding `.json*` at the hook
layer is the minimal correct fix.
After the fix:
- JSON-only staged sets cause lefthook to skip `lint-fix` (`no files for
inspection`) instead of mangling the file
- TS/JS/MD/CSS/YAML/etc. continue to flow through `oxlint --fix` +
`oxfmt --write` unchanged
- `oxlint --fix` was a no-op on JSON anyway (`0 files`), so removing it
costs nothing
A future oxfmt release that ships a configurable JSON formatter can
re-add these extensions; left a comment in `lefthook.yml` explaining the
rationale.
## Verification
Reproduced the bug locally with PR CopilotKit#5055's `packages/voice/package.json`
edit, then applied this fix and re-ran the same flow:
- **Before fix**: oxfmt mangled the file → `JSON.parse` threw at line 8
col 5
- **After fix**: lefthook skipped `lint-fix`, file remained valid strict
JSON
- **TS edit smoke test**: editing a `.ts` file in `packages/voice/src/`
still triggers `lint-fix` and runs cleanly through oxlint+oxfmt
This commit itself was created without `LEFTHOOK_EXCLUDE` — the full
pre-commit chain (`check-binaries`, `lint-fix`,
`test-and-check-packages`, `commitlint`) ran green because
`lefthook.yml` is not JSON.
## Related
- PR CopilotKit#5054 (`chore(deps): bump @ag-ui/langgraph to 0.0.34`) — bypassed
via `LEFTHOOK_EXCLUDE=lint-fix`
- PR CopilotKit#5055 (`chore(voice): move @copilotkit/runtime from dependencies to
peerDependencies`) — bypassed via `LEFTHOOK_EXCLUDE=lint-fix`, called
out the bug in the PR description
## Test plan
- [ ] CI green
- [ ] Future PRs touching `package.json` no longer need
`LEFTHOOK_EXCLUDE=lint-fix`1 file changed
Lines changed: 9 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
33 | 41 | | |
34 | 42 | | |
35 | 43 | | |
| |||
0 commit comments