forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-lint.sh
More file actions
executable file
·83 lines (76 loc) · 2.19 KB
/
Copy pathrun-lint.sh
File metadata and controls
executable file
·83 lines (76 loc) · 2.19 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
#!/bin/bash
# run-lint.sh — Run all pre-commit hooks manually (no git commit needed)
#
# Usage:
# ./github/scripts/run-lint.sh # all files (check only)
# ./github/scripts/run-lint.sh --files a.py b.py # specific files
#
# Timing (warm cache, M2 MacBook):
# black: ~0.3s ruff lint+format: ~0.5s
# detect-secrets: ~1.2s pre-commit-hooks: ~0.1s
# Total: ~2.1s
set -euo pipefail
# Script lives in .github/scripts/ — cd to repo root
cd "$(dirname "$0")/../.."
MODE="check" # "check" or "fix"
FILES_ARG=""
FAIL=0
if [ "${1:-}" = "--fix" ]; then
MODE="fix"
shift
fi
if [ "${1:-}" = "--files" ]; then
shift
FILES_ARG="$*"
fi
if [ -n "$FILES_ARG" ]; then
# Run on specific files
echo "🔍 Running lints on specified files ($MODE)..."
if command -v pre-commit &>/dev/null; then
pre-commit run --files $FILES_ARG || FAIL=1
else
echo "⚠️ pre-commit not installed, running tools directly"
for f in $FILES_ARG; do
[ "${f##*.}" != "py" ] && continue
if [ "$MODE" = "fix" ]; then
echo " black (fix) $f"
if ! black --line-length=120 --skip-string-normalization "$f" 2>&1; then
echo " ❌ black failed on $f"
FAIL=1
fi
echo " ruff (fix) $f"
if ! ruff check --fix --target-version py39 "$f" 2>&1; then
echo " ❌ ruff failed on $f"
FAIL=1
fi
else
echo " black (check) $f"
if ! black --check --line-length=120 --skip-string-normalization "$f" 2>&1; then
echo " ❌ black failed on $f"
FAIL=1
fi
echo " ruff (check) $f"
if ! ruff check --target-version py39 "$f" 2>&1; then
echo " ❌ ruff failed on $f"
FAIL=1
fi
fi
done
fi
else
# Run on all files
echo "🔍 Running lints on all files ($MODE)..."
if command -v pre-commit &>/dev/null; then
pre-commit run --all-files || FAIL=1
else
echo "⚠️ pre-commit not installed. Install with:"
echo " pip install pre-commit && pre-commit install"
exit 1
fi
fi
if [ "$FAIL" -ne 0 ]; then
echo ""
echo "❌ Lint errors found"
exit 1
fi
echo "✅ Lint complete"