Skip to content

Commit 27c05ef

Browse files
authored
dx: add lint/format to pre-commit hook (#51)
1 parent c03d44e commit 27c05ef

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

hooks/pre-commit

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,18 @@ if [ ${#blocked[@]} -gt 0 ]; then
7070
echo ""
7171
exit 1
7272
fi
73+
74+
# ── Lint & format staged JS/TS files ────────────────────────────────────────
75+
# Auto-fix lint/format issues on staged files and re-stage them.
76+
# Skips if biome is not available (e.g., agent runtime without devDependencies).
77+
78+
JS_FILES=$(echo "$STAGED" | grep -E '\.(ts|js|mjs|mts|cjs|cts|jsx|tsx)$' || true)
79+
80+
if [ -n "$JS_FILES" ] && command -v npx &>/dev/null; then
81+
# Check if biome is installed
82+
if npx biome --version &>/dev/null 2>&1; then
83+
# shellcheck disable=SC2086
84+
echo "$JS_FILES" | xargs npx biome check --write --no-errors-on-unmatched 2>/dev/null || true
85+
echo "$JS_FILES" | xargs git diff --name-only 2>/dev/null | xargs git add 2>/dev/null || true
86+
fi
87+
fi

0 commit comments

Comments
 (0)