-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-push
executable file
·40 lines (32 loc) · 887 Bytes
/
pre-push
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
#!/bin/sh
# before git commit, this hook enforces linting with JSHint and Google Closure Linter
jshintresult=$(jshint .)
ignored=""
# get ignored files and comma-separate them
ignored=$(tr '\n' ',' < .jshintignore)
# prepare the GCL command, excluding files if necessary
gclcommand="gjslint -r ."
if [ "$ignored" != "" ]; then
gclcommand+=" -x $ignored"
fi
gjslintresult=$($gclcommand)
valid=true
# empty response -> no errors
if [ "$jshintresult" != "" ]; then
printf "JSHint validation unsuccessful:\n$jshintresult\n"
valid=false
else
printf "JSHint validation successful\n"
fi
# check if the GCL result contains "Line" (meaning error(s) was found)
if [[ $gjslintresult == *Line* ]]; then
printf "\n\nClosure Linter validation unsuccessful:\n$gjslintresult\n"
valid=false
else
printf "Closure Linter validation successful\n"
fi
if ! $valid; then
exit 1
else
exit 0
fi