File tree Expand file tree Collapse file tree 1 file changed +35
-6
lines changed Expand file tree Collapse file tree 1 file changed +35
-6
lines changed Original file line number Diff line number Diff line change @@ -13,15 +13,44 @@ PASS=true
1313
1414echo -e " \nValidating Javascript:\n"
1515
16- # Check for eslint
17- which eslint & > /dev/null
18- if [[ " $? " == 1 ]]; then
19- echo -e " \t\033[41mPlease install ESlint\033[0m"
20- exit 1
16+ # Detect package manager
17+ if [ -f " pnpm-lock.yaml" ]; then
18+ PACKAGE_MANAGER=" pnpm"
19+ elif [ -f " yarn.lock" ]; then
20+ PACKAGE_MANAGER=" yarn"
21+ else
22+ PACKAGE_MANAGER=" npm"
23+ fi
24+
25+ # First check for local eslint installation
26+ if [ -f " node_modules/.bin/eslint" ]; then
27+ ESLINT=" ./node_modules/.bin/eslint"
28+ echo -e " \t\033[32mUsing project's local ESLint installation\033[0m"
29+ else
30+ echo -e " \t\033[33mNo local ESLint installation found. Installing...\033[0m"
31+ case $PACKAGE_MANAGER in
32+ " pnpm" )
33+ pnpm add -D eslint
34+ ;;
35+ " yarn" )
36+ yarn add -D eslint
37+ ;;
38+ * )
39+ npm install --save-dev eslint
40+ ;;
41+ esac
42+
43+ if [ -f " node_modules/.bin/eslint" ]; then
44+ ESLINT=" ./node_modules/.bin/eslint"
45+ echo -e " \t\033[32mSuccessfully installed ESLint locally\033[0m"
46+ else
47+ echo -e " \t\033[41mFailed to install ESLint locally. Please install it manually using your package manager.\033[0m"
48+ exit 1
49+ fi
2150fi
2251
2352for FILE in $STAGED_FILES ; do
24- eslint " $FILE "
53+ $ESLINT " $FILE "
2554
2655 if [[ " $? " == 0 ]]; then
2756 echo -e " \t\033[32mESLint Passed: $FILE \033[0m"
You can’t perform that action at this time.
0 commit comments