-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit-hook.sh
More file actions
29 lines (24 loc) · 1006 Bytes
/
Copy pathpre-commit-hook.sh
File metadata and controls
29 lines (24 loc) · 1006 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env sh
# Git pre-commit hook: analyse only staged .ts/.js files, block the commit if
# any exceed error thresholds. Fast (only touches what you're about to
# commit) and local (catches problems before they ever reach CI).
#
# Install:
# cp examples/ci-integration/pre-commit-hook.sh .git/hooks/pre-commit
# chmod +x .git/hooks/pre-commit
#
# Or wire it through husky (https://typicode.github.io/husky/):
# npx husky add .husky/pre-commit "$(cat examples/ci-integration/pre-commit-hook.sh | tail -n +2)"
STAGED=$(git diff --cached --name-only --diff-filter=ACM -- '*.ts' '*.tsx' '*.js' '*.jsx')
if [ -z "$STAGED" ]; then
exit 0
fi
echo "code-multivitals: checking $(echo "$STAGED" | wc -l | tr -d ' ') staged file(s)..."
# shellcheck disable=SC2086
npx code-multivitals $STAGED --profile default --max-errors 0
STATUS=$?
if [ $STATUS -ne 0 ]; then
echo ""
echo "code-multivitals: commit blocked — fix the errors above, or bypass with 'git commit --no-verify'."
fi
exit $STATUS