Skip to content

Commit 6030210

Browse files
Merge pull request #26 from ModusCreateOrg/adds-lizard
[NO-TICKET] Adds lizard as verification step before commit.
2 parents 077ff32 + 57673d2 commit 6030210

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

.husky/pre-commit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
sh ../lizard.sh
2+
13
cd frontend && npm run lint

lizard.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
# Check if lizard is installed
4+
if ! command -v lizard &> /dev/null; then
5+
echo "❌ lizard is not installed."
6+
echo "To install lizard globally, run:"
7+
echo " pip install lizard"
8+
exit 1
9+
fi
10+
11+
# Set the complexity threshold
12+
COMPLEXITY_LIMIT=10
13+
NLOC_LIMIT=250
14+
15+
# Get the list of files staged for commit
16+
FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.tsx$|\.ts$')
17+
18+
# Check if there are any files to analyze
19+
if [[ -z "$FILES" ]]; then
20+
echo "No Typescript files to check"
21+
exit 0 # No files to check, allow commit
22+
fi
23+
24+
echo "Running lizard check..."
25+
26+
# Initialize error list
27+
ERROR_LIST=""
28+
29+
# Run lizard and capture output
30+
for FILE in $FILES; do
31+
# Run lizard analysis for the file
32+
OUTPUT=$(lizard -C $COMPLEXITY_LIMIT -Tnloc=$NLOC_LIMIT -w --warning-msvs "$FILE")
33+
ERROR_CODE=$?
34+
35+
if [[ "$ERROR_CODE" -ne 0 ]]; then
36+
ERROR_LIST+="$OUTPUT\n"
37+
fi
38+
done
39+
40+
# Check if there were any errors
41+
if [[ -n "$ERROR_LIST" ]]; then
42+
echo "❌ Commit aborted due to the errors in the following files:"
43+
echo "$ERROR_LIST"
44+
echo "Limits are: Code Complexity (CCN)=$COMPLEXITY_LIMIT and Number of Lines (NLOC)=$NLOC_LIMIT"
45+
exit 1
46+
else
47+
echo "✅ Complexity check passed."
48+
exit 0
49+
fi
50+
51+

0 commit comments

Comments
 (0)