11#! /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
33
44#  Function to check if a command exists
55command_exists () {
66  command  -v " $1 " > /dev/null 2>&1 
77}
88
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+ 
928#  Check if Snyk is installed
1029if  !  command_exists snyk;  then 
1130  echo  " Error: Snyk is not installed. Please install it and try again." 
@@ -18,12 +37,6 @@ if ! command_exists talisman; then
1837  exit  1
1938fi 
2039
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- 
2740#  Initialize variables to track scan results
2841snyk_failed=false
2942talisman_failed=false
@@ -63,7 +76,7 @@ if [ "$snyk_failed" = true ] || [ "$talisman_failed" = true ]; then
6376  exit  1
6477fi 
6578
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." 
6881rm -f snyk_output.log talisman_output.log
6982exit  0
0 commit comments