chore: add lefthook pre-commit hook for oxfmt#274
Conversation
|
@copilot can you help me resolve the branch conflict in pnpm-lock.yaml |
There was a problem hiding this comment.
Pull request overview
Adds local pre-commit automation so staged files are formatted with oxfmt before committing, reducing CI failures caused by unformatted changes.
Changes:
- Add
husky+lint-stageddev dependencies and apreparescript to install hooks onpnpm install. - Configure
lint-stagedto runoxfmtfor common source/document formats. - Update lockfile to include the new toolchain (and reflect dependency re-resolution).
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
package.json |
Adds husky/lint-staged, wires prepare, and defines the lint-staged file matcher to run oxfmt. |
.husky/pre-commit |
Introduces the pre-commit hook entrypoint that triggers lint-staged. |
pnpm-lock.yaml |
Captures dependency graph changes from adding husky and lint-staged (plus related re-resolution). |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (1)
.husky/pre-commit:2
.husky/pre-commitis missing a shebang / Husky wrapper. Git executes hooks as standalone executables; without a shebang (and typically Husky’s_/husky.shbootstrap), this hook will fail with an “exec format error” on POSIX systems and won’t runlint-staged. Add the standard Husky hook header and ensure the hook file is executable in git.
pnpm exec lint-staged
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Resolved in |
commit: |
Run oxfmt on staged ts/tsx/js/jsx/mjs/cjs/json/jsonc/md/mdx/yaml/yml/css/html files before commit, preventing fmt:check failures in CI for cases that the local pnpm fmt invocation hasn't caught. Lefthook is used across other Tailor repos, so we match that tooling instead of husky + lint-staged for consistency. - lefthook@2.1.6 added as a root devDependency - prepare script runs `lefthook install` so contributors get the hook on pnpm install - lefthook.yml defines the pre-commit oxfmt command with stage_fixed so formatter changes are re-staged - allowBuilds marks lefthook: false since the root prepare script handles hook installation Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
5cb7977 to
f3e272a
Compare
|
@copilot I've updated it to use lefthook instead, can you verify if this new approach will work? |
Yes — I verified the lefthook approach on commit
I also checked recent branch workflows — no failing CI runs for this head SHA. |
Summary
Add a pre-commit hook that runs
oxfmton staged source files, preventingpnpm fmt:checkfailures from surfacing in CI for changes that weren't formatted locally before the commit.Uses lefthook to match the tooling already in use across other Tailor repos.
Changes
package.json— addslefthook@2.1.6as a root devDependency and apreparescript (lefthook install) so contributors get the hook onpnpm install.lefthook.yml— pre-commit config runningpnpm exec oxfmton staged files matching:oxfmtactually formats across the workspace today).stage_fixed: truere-stages files that the formatter rewrites, so the formatted output lands in the commit.pnpm-workspace.yaml— declareslefthook: falseunderallowBuilds. Lefthook's npm package ships apostinstallhook installer, but we intentionally let the rootpreparescript handle that, so the dep-side script stays disabled (consistent with the workspace's strict supply-chain policy).pnpm-lock.yaml— adds the lefthook subtree (+10/-7 packages, mostly platform-specific binary wrappers).Notes for reviewers
--trust-policy-excludeflags forsemver@6.3.1,reselect@5.1.1, and@swc/core@1.12.11. These are pre-existingtrustPolicy: no-downgradetripwires (earlier published versions had provenance attestations, current ones don't); unrelated to this change.pnpm install --frozen-lockfilecleanly, so CI is unaffected.@tailor-platform/app-shell's public surface.mainand force-pushed; an earlier husky/lint-staged commit was dropped from history in favour of this single lefthook commit.Test plan
pnpm fmt:checkpasses against the new lockfileoxfmtreformats and re-stages the formatted contentoxfmtran against its own staged files), proving the hook is wired correctly