-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpre-commit
More file actions
executable file
·124 lines (109 loc) · 4.52 KB
/
Copy pathpre-commit
File metadata and controls
executable file
·124 lines (109 loc) · 4.52 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/zsh
# GoProX Pre-commit Hook
# Runs comprehensive checks before allowing commits
echo "🔍 Running pre-commit checks..."
# Check for TODO/FIXME comments in staged files
if git diff --cached --name-only | xargs grep -l "TODO\|FIXME" 2>/dev/null; then
echo "⚠️ Warning: Found TODO/FIXME comments in staged files"
echo " Consider addressing these before committing"
fi
# Check for large files (>10MB)
large_files=$(git diff --cached --name-only | xargs ls -la 2>/dev/null | awk '$5 > 10485760 {print $9}')
if [[ -n "$large_files" ]]; then
echo "⚠️ Warning: Found files larger than 10MB"
echo " Consider using Git LFS for large files"
fi
# YAML Linting (if yamllint is available)
if command -v yamllint &> /dev/null; then
echo "🔍 Running YAML linting..."
# Get staged YAML files
yaml_files=$(git diff --cached --name-only | grep -E '\.(yml|yaml)$' || true)
if [[ -n "$yaml_files" ]]; then
for file in $yaml_files; do
if [[ -f "$file" ]]; then
if ! yamllint -c .yamllint "$file" 2>/dev/null; then
echo "❌ YAML linting failed for $file"
echo " Run: ./scripts/maintenance/fix-yaml-formatting.zsh to auto-fix"
exit 1
fi
fi
done
echo "✅ YAML linting passed"
else
echo "ℹ️ No YAML files staged for linting"
fi
else
echo "ℹ️ yamllint not available - skipping YAML linting"
echo " Install with: brew install yamllint or pip3 install yamllint"
fi
# Check for logger usage in zsh scripts (per design principles)
echo "🔍 Checking logger usage in zsh scripts..."
zsh_files=$(git diff --cached --name-only | grep -E '\.zsh$' || true)
if [[ -n "$zsh_files" ]]; then
for file in $zsh_files; do
if [[ -f "$file" ]]; then
# Skip if it's a core module (they define the logger)
if [[ "$file" != *"/core/"* ]]; then
if ! grep -q "log_" "$file"; then
echo "⚠️ Warning: $file doesn't use logger functions"
echo " Consider using log_info, log_error, etc. for consistent logging"
fi
fi
fi
done
fi
# JSON Linting (if jsonlint is available)
if command -v jsonlint &> /dev/null; then
echo "🔍 Running JSON linting..."
# Get staged JSON files
json_files=$(git diff --cached --name-only | grep -E '\.json$' || true)
if [[ -n "$json_files" ]]; then
for file in $json_files; do
if [[ -f "$file" ]]; then
if ! jsonlint "$file" >/dev/null 2>&1; then
echo "❌ JSON linting failed for $file"
echo " Run: jsonlint $file to see errors"
exit 1
fi
fi
done
echo "✅ JSON linting passed"
else
echo "ℹ️ No JSON files staged for linting"
fi
else
echo "ℹ️ jsonlint not available - skipping JSON linting"
echo " Install with: npm install -g jsonlint"
fi
# Check for file headers (copyright, license, usage patterns)
echo "🔍 Checking file headers..."
staged_files=$(git diff --cached --name-only || true)
if [[ -n "$staged_files" ]]; then
for file in $staged_files; do
if [[ -f "$file" ]]; then
# Check for copyright notices in source files
if [[ "$file" =~ \.(zsh|md|yaml|yml|json)$ ]]; then
if ! head -10 "$file" | grep -q "Copyright\|copyright"; then
echo "⚠️ Warning: $file missing copyright notice"
echo " Consider adding copyright header to file"
fi
fi
# Check for license headers in appropriate files
if [[ "$file" =~ \.(zsh|md)$ ]]; then
if ! head -10 "$file" | grep -q "License\|license"; then
echo "⚠️ Warning: $file missing license header"
echo " Consider adding license information to file"
fi
fi
# Check for usage patterns in documentation
if [[ "$file" =~ \.md$ ]] && [[ "$file" != README.md ]] && [[ "$file" != CONTRIBUTING.md ]]; then
if ! head -10 "$file" | grep -q "Usage\|usage"; then
echo "⚠️ Warning: $file missing usage documentation"
echo " Consider adding usage examples to documentation"
fi
fi
fi
done
fi
echo "✅ Pre-commit checks completed"
exit 0