1
1
#! /usr/bin/env sh
2
- # Pre-commit hook to run Snyk and Talisman scans, completing both before deciding to commit
2
+ # Pre-commit hook to run lint, Snyk and Talisman scans, completing all before deciding to commit
3
3
4
4
# Function to check if a command exists
5
5
command_exists () {
6
6
command -v " $1 " > /dev/null 2>&1
7
7
}
8
8
9
+ # Allow bypassing the hook with an environment variable
10
+ if [ " $SKIP_HOOK " = " 1" ]; then
11
+ echo " Skipping lint, Snyk and Talisman scans (SKIP_HOOK=1)."
12
+ exit 0
13
+ fi
14
+
15
+ # Run ESLint check first
16
+ echo " Running ESLint check..."
17
+ npm run lint
18
+ lint_exit_code=$?
19
+
20
+ if [ $lint_exit_code -ne 0 ]; then
21
+ echo " ESLint check failed. Please fix the linting issues and try again."
22
+ echo " You can run 'npm run format' to auto-fix most issues."
23
+ exit 1
24
+ fi
25
+
26
+ echo " ESLint check passed."
27
+
9
28
# Check if Snyk is installed
10
29
if ! command_exists snyk; then
11
30
echo " Error: Snyk is not installed. Please install it and try again."
@@ -18,12 +37,6 @@ if ! command_exists talisman; then
18
37
exit 1
19
38
fi
20
39
21
- # Allow bypassing the hook with an environment variable
22
- if [ " $SKIP_HOOK " = " 1" ]; then
23
- echo " Skipping Snyk and Talisman scans (SKIP_HOOK=1)."
24
- exit 0
25
- fi
26
-
27
40
# Initialize variables to track scan results
28
41
snyk_failed=false
29
42
talisman_failed=false
@@ -63,7 +76,7 @@ if [ "$snyk_failed" = true ] || [ "$talisman_failed" = true ]; then
63
76
exit 1
64
77
fi
65
78
66
- # If both scans pass, allow the commit
67
- echo " All scans passed. Proceeding with commit.cd ."
79
+ # If all checks pass, allow the commit
80
+ echo " All checks passed (ESLint, Snyk, Talisman) . Proceeding with commit."
68
81
rm -f snyk_output.log talisman_output.log
69
82
exit 0
0 commit comments