Files
copilotkit__copilotkit/lefthook.yml
Jordan Ritter a8fa1a3b11 fix(lefthook): exclude json/jsonc/json5 from oxlint/oxfmt to prevent JSON5 mangling
The lint-fix pre-commit step runs `oxlint --fix` + `oxfmt --write` over
staged files. When `package.json` is part of the staged set, oxfmt
rewrites the file into JSON5 syntax (4-space indent, trailing commas
after the last key in every object, compacted single-line objects).
The result is invalid strict JSON that pnpm rejects with
`ERR_PNPM_JSON_PARSE` at line 8 column 5, blocking every commit that
touches any `package.json`.

This was bypassed in PRs #5054 and #5055 via `LEFTHOOK_EXCLUDE=lint-fix`;
this commit fixes it at the source by removing `json,jsonc,json5` from
the lint-fix glob.

Reproduction (with the buggy glob):
  - Apply PR #5055's edit to packages/voice/package.json
  - git add + run `lefthook run pre-commit --command lint-fix`
  - oxfmt logs "1 file reformatted"
  - JSON.parse / pnpm install now fail on the rewritten file

After the fix:
  - JSON-only staged sets cause lefthook to skip lint-fix ("no files for
    inspection") rather than mangle the JSON
  - TS/JS/etc. continue to flow through oxlint --fix + oxfmt --write
    unchanged
  - JSON formatting is left to pnpm and manual editing, both of which
    produce strict 2-space JSON

oxfmt 0.36.0 exposes no per-file-type knob (printWidth/proseWrap/
ignorePatterns only); excluding json/jsonc/json5 from the glob is the
minimal correct fix. A future oxfmt upgrade that ships a json formatter
configurable via `.oxfmtrc.json` can re-add these extensions.

This commit itself is being landed with `LEFTHOOK_EXCLUDE=lint-fix`
because the bug being fixed currently blocks any path that exercises the
lint-fix hook. The change touches only `lefthook.yml`, which is not a
JSON file and would not be mangled — the exclude is purely defensive.
2026-05-27 13:49:31 -07:00

85 lines
3.4 KiB
YAML

output:
- meta
- summary
- success
- failure
- execution
- execution_out
- execution_info
- skips
pre-commit:
parallel: true
commands:
check-binaries:
tags: binaries
run: bash scripts/hooks/check-binaries.sh
sync-lockfile:
tags: lockfile
glob: "{packages,examples,showcase/scripts}/**/package.json"
run: pnpm i --lockfile-only
stage_fixed: true
lint-fix:
tags: lint
# Scope oxlint and oxfmt to just the files staged for commit — running
# `--fix .` / `--write .` across the whole monorepo on every commit is
# both slow and blurs the hook's purpose (touch files that aren't part
# of this change). Guard against empty `{staged_files}` expansion: when
# a commit touches only non-matching files (markdown, YAML), lefthook
# still invokes this hook with an empty expansion, and oxlint/oxfmt
# would default to operating on the current directory, defeating the
# scoping entirely. stage_fixed re-stages whatever the hooks modify.
# Intentionally excludes json/jsonc/json5: oxfmt --write rewrites JSON
# files into JSON5 syntax (4-space indent, trailing commas, compact
# objects) when invoked via lefthook with staged file paths. The result
# is invalid strict JSON that pnpm rejects with ERR_PNPM_JSON_PARSE,
# blocking every commit that touches a package.json (see PRs #5054,
# #5055). JSON formatting is owned by pnpm/manual editing; oxfmt has
# no per-file knobs to keep package.json valid, so the only safe fix
# is to keep .json* out of this hook entirely.
glob: "*.{js,jsx,ts,tsx,mjs,cjs,md,css,yml,yaml,html,vue,py}"
# Mirror the ignorePatterns in .oxlintrc.json / .oxfmtrc.json at the
# hook layer. Without this, a docs-only commit expands {staged_files}
# to a single docs/** path; oxlint silently processes 0 files, then
# oxfmt exits 2 with "Expected at least one target file" and blocks
# the commit.
exclude:
- "docs/**"
- "showcase/aimock/shared/**"
- "showcase/aimock/d4/**"
- "showcase/aimock/d6/**"
# Use `set --` so the staged files become positional args; this is the
# only shell-portable way to test "are there any" without breaking on
# multi-file expansion. The old `[ -n "{staged_files}" ]` form failed
# with `sh: 1: [: <path>: unexpected operator` because lefthook
# interpolates the file list as space-separated words, not a single
# quoted string, so [ saw 3+ args and tried to parse a binary op.
run: |
set -- {staged_files}
if [ "$#" -gt 0 ]; then
pnpm exec oxlint --fix "$@" &&
pnpm exec oxfmt --write "$@" ;
ruff format "$@" 2>/dev/null || true
fi
stage_fixed: true
test-and-check-packages:
tags: test-packages
env:
NX_TUI: "false"
run: pnpm run test && pnpm run check:packages
check-plugin-skills:
tags: plugin-skills
glob: "{packages/*/skills/**,skills/runtime/**,skills/react-core/**,skills/a2ui-renderer/**,scripts/sync-plugin-skills.ts,.claude-plugin/**}"
run: pnpm check:plugin-skills
fail_text: |
Plugin skill mirror is out of sync with the Intent source.
Run: pnpm sync:plugin-skills
Then stage the changes and re-commit.
commit-msg:
commands:
commitlint:
tags: commitlint
run: pnpm commitlint --edit {1}