Skip to content

Commit c406f10

Browse files
committed
feat(./scripts/validate-eslint.sh): add validate eslint sh to check js linting
1 parent 68db05e commit c406f10

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

scripts/validate-eslint.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 $?

0 commit comments

Comments
 (0)