Skip to content

Commit 0ca3099

Browse files
committed
fix: replace manual oxfmt shell script with lint-staged
The pre-commit hook used a manual shell script to format staged files, but `2>/dev/null || true` swallowed errors silently. When oxfmt failed, unformatted code was committed and only caught later by the pre-push `oxfmt --check`, blocking pushes with pre-existing formatting drift. Switch to lint-staged (the official oxfmt recommendation) which handles staged file filtering, formatting, and re-staging correctly — including partial staging.
1 parent fd61b59 commit 0ca3099

3 files changed

Lines changed: 202 additions & 47 deletions

File tree

.githooks/pre-commit

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,4 @@ set -eu
33

44
pnpm hooks:pre-commit
55

6-
# Auto-fix formatting on staged files and re-stage them
7-
STAGED=$(git diff --cached --name-only --diff-filter=ACMR)
8-
if [ -n "$STAGED" ]; then
9-
WWW_STAGED=$(echo "$STAGED" | grep '^apps/www/' || true)
10-
if [ -n "$WWW_STAGED" ]; then
11-
echo "$WWW_STAGED" | sed 's|^apps/www/||' | (cd apps/www && xargs oxfmt 2>/dev/null) || true
12-
echo "$WWW_STAGED" | xargs git add
13-
fi
14-
fi
6+
pnpm lint-staged

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,15 @@
3434
},
3535
"devDependencies": {
3636
"@changesets/cli": "^2.29.8",
37+
"lint-staged": "^16.4.0",
3738
"tsx": "^4.21.0"
3839
},
3940
"engines": {
4041
"node": ">=20",
4142
"pnpm": ">=8.0.0"
4243
},
44+
"lint-staged": {
45+
"apps/www/**/*.{ts,tsx,js,jsx,mjs,cjs,css,json,jsonc}": "oxfmt --no-error-on-unmatched-pattern"
46+
},
4347
"packageManager": "pnpm@10.11.0"
4448
}

0 commit comments

Comments
 (0)