Repository navigation
Expand file tree
/
Copy pathpre-commit
More file actions
executable file
·89 lines (74 loc) · 2.34 KB
/
Copy pathpre-commit
File metadata and controls
executable file
·89 lines (74 loc) · 2.34 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/sh
export LC_ALL=C NO_XFAIL=1
LINTED_DIRECTORIES="apps shared build/test/unit"
JSHINT_EXECUTABLE="node_modules/.bin/jshint"
JSHINT_XFAIL_LIST="build/jshint/xfail.list"
JSHINT_ARGS="--reporter=build/jshint/xfail $JSHINT_ARGS"
excluded_list=".jshintignore"
jshint_information() {
echo "Please read https://github.com/mozilla-b2g/gaia/tree/master/build/jshint/README.md for more information.\n"
}
if [ ! -r $excluded_list ];
then
exit 0
fi
if [ ! -r "$JSHINT_XFAIL_LIST" ];
then
# early bailout, this commit hook is newer than the gaia code it runs in
exit 0
fi
hash gjslint > /dev/null 2>&1
if [ $? -eq 1 ];
then
echo >&2 "You should install gjslint to lint your patch"
echo >&2 "https://developers.google.com/closure/utilities/docs/linter_howto"
exit 0
fi
hash node > /dev/null 2>&1
if [ $? -eq 1 ];
then
echo >&2 "You should install node to lint your patch"
echo >&2 "http://nodejs.org/download/"
exit 0
fi
if [ ! -x "$JSHINT_EXECUTABLE" ];
then
echo >&2 'You should run `npm install` to lint your patch'
exit 0
fi
changed_files=`git diff --staged --name-only --diff-filter=ACMRT -- $LINTED_DIRECTORIES | grep '\.js$'`
if [ -z "$changed_files" ] ; then
exit 0
fi
# gjslint: only test files xfailed in jshint
# echo with the quotes keeps the whitespace -- comm needs newlines, but
# LINTED_FILES needs to be space-separated
# Note also that xfail.list _must_ be sorted.
xfailed=`echo "$changed_files" | sort | comm -12 "$JSHINT_XFAIL_LIST" - | tr '[:space:]' ' '`
gjslint_result=0
if [ -n "$xfailed" ] ; then
echo "gjslint check:"
LINTED_FILES="$xfailed" make -s gjslint
gjslint_result=$?
echo
fi
echo "jshint check:"
# warn about files being xfailed
for file in $changed_files ; do
one_was_ignored=""
if grep -q $file "$JSHINT_XFAIL_LIST" ; then
one_was_ignored="1"
echo "$file: jshint errors are ignored. Please consider fixing lint errors and removing it from $JSHINT_XFAIL_LIST."
fi
done
test -n "$one_was_ignored" && jshint_information
# using the real jshint instead of the make target to prevent running npm
# install at commit time
$JSHINT_EXECUTABLE $JSHINT_ARGS $changed_files
jshint_result=$?
if [ $gjslint_result -ne 0 -o $jshint_result -ne 0 ] ; then
echo "There were errors while linting the files, please see above."
test $jshint_result -ne 0 && jshint_information
exit 1
fi
echo "No errors - committing"