-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode-quality.sh
More file actions
executable file
·74 lines (67 loc) · 2.24 KB
/
code-quality.sh
File metadata and controls
executable file
·74 lines (67 loc) · 2.24 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
#!/usr/bin/env bash
"""
Code quality checking hook for Husky-style pre-commit setup.
This hook runs Black, isort, flake8, and Bandit for code quality.
"""
echo "🐍 Running Python code quality checks..."
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check Black formatting
echo " - Checking code formatting with Black..."
if command_exists black; then
if black --check --diff .; then
echo " ✅ Black formatting check passed"
else
echo " ❌ Black formatting issues found"
echo " 💡 Run 'black .' to fix formatting"
exit 1
fi
else
echo " ⚠️ Black not installed, skipping formatting check"
echo " 💡 Install with: pip install black"
fi
# Check isort import sorting
echo " - Checking import sorting with isort..."
if command_exists isort; then
if isort --check-only --diff .; then
echo " ✅ isort import sorting check passed"
else
echo " ❌ isort import sorting issues found"
echo " 💡 Run 'isort .' to fix import sorting"
exit 1
fi
else
echo " ⚠️ isort not installed, skipping import sorting check"
echo " 💡 Install with: pip install isort"
fi
# Check flake8 linting
echo " - Running linting with flake8..."
if command_exists flake8; then
if flake8 --max-line-length=88 --extend-ignore=E203,W503 .; then
echo " ✅ flake8 linting check passed"
else
echo " ❌ flake8 linting issues found"
echo " 💡 Fix the linting issues above"
exit 1
fi
else
echo " ⚠️ flake8 not installed, skipping linting check"
echo " 💡 Install with: pip install flake8"
fi
# Check Bandit security linting
echo " - Running security linting with Bandit..."
if command_exists bandit; then
if bandit -r . -f json -o bandit-report.json; then
echo " ✅ Bandit security linting check passed"
else
echo " ❌ Bandit found security issues"
echo " 💡 Review bandit-report.json for details"
exit 1
fi
else
echo " ⚠️ Bandit not installed, skipping security linting"
echo " 💡 Install with: pip install bandit"
fi
echo "✅ All code quality checks passed!"