generated from ModusCreateOrg/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlizard.sh
59 lines (48 loc) · 1.53 KB
/
lizard.sh
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
#!/bin/bash
# Check if lizard is installed
if command -v lizard &> /dev/null; then
echo "✅ lizard found in PATH"
elif [ -x ~/.local/bin/lizard ]; then
echo "✅ lizard found in user bin, adding to PATH"
export PATH="$HOME/.local/bin:$PATH"
elif [ -x /usr/local/bin/lizard ]; then
echo "✅ lizard found in system bin, adding to PATH"
export PATH="/usr/local/bin:$PATH"
else
echo "❌ lizard is not installed."
echo "To install lizard globally, run:"
echo " pip install lizard"
exit 1
fi
# Set the complexity threshold
COMPLEXITY_LIMIT=10
NLOC_LIMIT=250
# Get the list of files staged for commit
FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.tsx$|\.ts$')
# Check if there are any files to analyze
if [ -z "$FILES" ]; then
echo "No Typescript files to check"
exit 0 # No files to check, allow commit
fi
echo "Running lizard check..."
# Initialize error list
ERROR_LIST=""
# Run lizard and capture output
for FILE in $FILES; do
# Run lizard analysis for the file
OUTPUT=$(lizard -C $COMPLEXITY_LIMIT -Tnloc=$NLOC_LIMIT -w --warning-msvs "$FILE")
ERROR_CODE=$?
if [ "$ERROR_CODE" -ne 0 ]; then
ERROR_LIST+="$OUTPUT\n"
fi
done
# Check if there were any errors
if [ -n "$ERROR_LIST" ]; then
echo "❌ Commit aborted due to the errors in the following files:"
echo "$ERROR_LIST"
echo "Limits are: Code Complexity (CCN)=$COMPLEXITY_LIMIT and Number of Lines (NLOC)=$NLOC_LIMIT"
exit 1
else
echo "✅ Complexity check passed."
exit 0
fi