File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+
3+ # CREDITS: https://gist.github.com/linhmtran168/2286aeafe747e78f53bf
4+ # MODIFIED: t.hamoudi
5+ # MAINTAINED: admin@josa.ngo
6+
7+ STAGED_FILES=$( git diff --cached --name-only --diff-filter=ACM | grep -E " (.js$|.jsx$|.ts$|.tsx$)" )
8+
9+ if [[ " $STAGED_FILES " = " " ]]; then
10+ exit 0
11+ fi
12+
13+ PASS=true
14+
15+ echo -e " \nValidating Javascript:\n"
16+
17+ # Check for eslint
18+ which eslint & > /dev/null
19+ if [[ " $? " == 1 ]]; then
20+ echo -e " \t\033[41mPlease install ESlint\033[0m"
21+ exit 1
22+ fi
23+
24+ for FILE in $STAGED_FILES ; do
25+ eslint " $FILE "
26+
27+ if [[ " $? " == 0 ]]; then
28+ echo -e " \t\033[32mESLint Passed: $FILE \033[0m"
29+ else
30+ echo -e " \t\033[41mESLint Failed: $FILE \033[0m"
31+ PASS=false
32+ fi
33+ done
34+
35+ echo -e " \nJavascript validation completed!\n"
36+
37+ if ! $PASS ; then
38+ echo -e " \033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass ESLint but do not. Please fix the ESLint errors and try again."
39+ exit 1
40+ else
41+ echo -e " \033[42mCOMMIT SUCCEEDED\033[0m"
42+ fi
43+
44+ exit $?
You can’t perform that action at this time.
0 commit comments