-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpre-commit.sh
More file actions
executable file
·62 lines (53 loc) · 1.32 KB
/
pre-commit.sh
File metadata and controls
executable file
·62 lines (53 loc) · 1.32 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
#!/usr/bin/env bash
# Pre-commit checks: runs lint and type-checking before allowing a commit.
# Install as a git hook automatically via `npm install` (see prepare script).
# Run manually: bash scripts/pre-commit.sh
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
pass() { echo -e "${GREEN}✔${NC} $1"; }
fail() { echo -e "${RED}✖${NC} $1"; }
info() { echo -e "${YELLOW}▶${NC} $1"; }
echo ""
info "Running pre-commit checks..."
echo ""
FAILED=0
# 1. Prettier formatting check
info "Checking code formatting (Prettier)..."
if npx prettier --check . --log-level warn; then
pass "Formatting OK"
else
fail "Formatting issues found. Run: npm run format"
FAILED=1
fi
echo ""
# 2. ESLint
info "Running ESLint..."
if npx eslint --ignore-pattern .svelte-kit/output .; then
pass "ESLint OK"
else
fail "ESLint errors found."
FAILED=1
fi
echo ""
# 3. TypeScript + Svelte type checking
info "Running TypeScript / Svelte checks..."
if npm run check --silent; then
pass "Type checks OK"
else
fail "Type errors found. Fix them before committing."
FAILED=1
fi
echo ""
# Summary
if [ "$FAILED" -eq 0 ]; then
echo -e "${GREEN}All pre-commit checks passed.${NC}"
echo ""
exit 0
else
echo -e "${RED}One or more pre-commit checks failed. Commit aborted.${NC}"
echo ""
exit 1
fi