-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathcheck-js.sh
46 lines (33 loc) · 904 Bytes
/
check-js.sh
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
42
43
44
45
46
#!/bin/bash
# Basado en https://gist.github.com/linhmtran168/2286aeafe747e78f53bf
TARGET_BRANCH_SHA=`git rev-parse origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}`
STAGED_FILES=`git diff $TARGET_BRANCH_SHA...HEAD --name-only --diff-filter=ACM | grep ".*\.js$"`
if [[ "$STAGED_FILES" = "" ]]; then
exit 0
fi
PASS=true
echo "\nValidating Javascript code:\n"
# Check for eslint
which eslint &> /dev/null
if [[ "$?" == 1 ]]; then
echo "Please install ESlintm"
exit 1
fi
for FILE in $STAGED_FILES
do
eslint "$FILE"
if [[ "$?" == 0 ]]; then
echo "ESLint Passed: $FILE"
else
echo "ESLint Failed: $FILE"
PASS=false
fi
done
echo "\nJavascript validation completed!\n"
if ! $PASS; then
echo "COMMIT FAILED:\033[0m Your commit contains files that should pass ESLint but do not. Please fix the ESLint errors and try again.\n"
exit 1
else
echo "COMMIT SUCCEEDED"
fi
exit $?