-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpre-commit-template
More file actions
41 lines (31 loc) · 886 Bytes
/
pre-commit-template
File metadata and controls
41 lines (31 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/sh
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".jsx\{0,1\}$"| grep -v ".ejs" | grep -v "node_modules")
if [[ "$STAGED_FILES" = "" ]]; then
exit 0
fi
PASS=true
printf "\nValidating Javascript:\n\n"
# Check for eslint
ESLINT="$(git rev-parse --show-toplevel)/node_modules/.bin/eslint"
if [[ ! -x "$ESLINT" ]]; then
printf "Please install ESlint (npm i --save --save-exact --dev eslint)\n"
exit 1
fi
for FILE in $STAGED_FILES
do
"$ESLINT" "$FILE"
if [[ "$?" == 0 ]]; then
printf "ESLint Passed: $FILE\n"
else
printf "ESLint Failed: $FILE\n"
PASS=false
fi
done
printf "\nJavascript validation completed!\n\n"
if ! $PASS; then
printf "COMMIT FAILED: Your commit contains files that should pass ESLint but do not. Please fix the ESLint errors and try again.\n\n"
exit 1
else
printf "COMMIT SUCCEEDED\n\n"
fi
exit $?