-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathgit-hook
executable file
·39 lines (32 loc) · 1.11 KB
/
git-hook
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
#!/usr/bin/env bash
# Redirect output to stderr.
exec 1>&2
STAGED_FILES="$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.m?js$')"
if [[ "$STAGED_FILES" = "" ]]; then
printf "\t\033[32mESLint Passed: no modified .mjs files found.\033[0m\n"
exit 0
fi
if ! yarn run eslint; then
printf "\t\033[31mESLint not installed.\033[0m (Please run \`\033[1myarn install\033[0m\`.)\n"
exit 1
fi
PASS=true
for FILE in $STAGED_FILES; do
if yarn run eslint --no-eslintrc --config .github/eslintrc.yml -- "$FILE" ; then
printf "\t\033[32mESLint Passed\033[0m: %s\n" "$FILE"
else
printf "\t\033[31mESLint Failed\033[0m: %s\n" "$FILE"
PASS=false
fi
done
if "$PASS"; then
echo
printf "\t\033[32;1mESLint: COMMIT SUCCEEDED\033[0m\n"
else
echo
printf "\t\033[41;1mESLint: COMMIT FAILED.\033[0m\n"
printf "\t\033[31;1mYour commit contains files that should pass ESLint but do not.\033[0m\n"
printf "\t\033[31;1mPlease fix the ESLint errors and try again.\033[0m\n"
printf "\t(You can try \`\033[1myarn run eslint --ext .mjs . --fix\033[0m\` for auto-fix and don't forget to run \`\033[1mgit add\033[0m\`.)\n"
exit 1
fi