-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit.example
More file actions
72 lines (59 loc) · 1.69 KB
/
pre-commit.example
File metadata and controls
72 lines (59 loc) · 1.69 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env sh
# Git pre-commit hook to ensure code quality
# To enable this hook, copy it to .git/hooks/pre-commit and make it executable:
# cp .githooks/pre-commit.example .git/hooks/pre-commit
# chmod +x .git/hooks/pre-commit
# Exit on any error
set -e
echo "🔍 Running pre-commit checks..."
# Check if we have any staged files
if git diff --cached --quiet; then
echo "ℹ️ No staged changes found"
exit 0
fi
# Get list of staged files
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(js|jsx|ts|tsx|svelte)$' || true)
if [ -z "$STAGED_FILES" ]; then
echo "ℹ️ No JavaScript/TypeScript/Svelte files to check"
exit 0
fi
echo "📝 Files to check:"
echo "$STAGED_FILES" | sed 's/^/ - /'
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check if bun is available, fallback to npm
if command_exists bun; then
RUNNER="bun run"
elif command_exists npm; then
RUNNER="npm run"
else
echo "❌ Neither bun nor npm found. Please install one of them."
exit 1
fi
echo ""
echo "🎨 Checking code formatting..."
if ! $RUNNER format:check; then
echo "❌ Code formatting issues found!"
echo "💡 Run '$RUNNER format' to fix formatting issues"
exit 1
fi
echo ""
echo "🔧 Running ESLint..."
if ! $RUNNER lint:check; then
echo "❌ ESLint issues found!"
echo "💡 Run '$RUNNER lint' to auto-fix issues, or '$RUNNER lint:check' to see them"
exit 1
fi
echo ""
echo "📋 Running TypeScript check..."
if ! $RUNNER check; then
echo "❌ TypeScript errors found!"
echo "💡 Fix TypeScript errors before committing"
exit 1
fi
echo ""
echo "✅ All pre-commit checks passed!"
echo "🚀 Ready to commit"
exit 0