forked from mozilla-b2g/gaia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit
More file actions
executable file
·111 lines (90 loc) · 3.07 KB
/
Copy pathpre-commit
File metadata and controls
executable file
·111 lines (90 loc) · 3.07 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/sh
export LC_ALL=C NO_XFAIL=1
############################### JS Lint #####################################
LINTED_DIRECTORIES="apps shared build/test/unit test_apps/demo-keyboard"
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
js_changed_files=`git diff --staged --name-only --diff-filter=ACMRT -- $LINTED_DIRECTORIES | grep '\.js$'`
if [ -n "$js_changed_files" ]
then
# 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 "$js_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 $js_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 $js_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
fi
############################### CSS Lint #####################################
css_changed_files=`git diff --staged --name-only --diff-filter=ACMRT -- apps shared/ | grep '\.css$' | tr '\n' ' '`
if [ -n "$css_changed_files" ]
then
XULRUNNER_SDK=$(make xulrunner_sdk)
XPCSHELL_SDK=$(make xpcshell_sdk)
GAIA_DIR=$(pwd) $XULRUNNER_SDK $XPCSHELL_SDK \
-f build/xpcshell-commonjs.js \
-e "quit(require('csslint').lint('$(pwd)', '$css_changed_files'));"
if [ $? -ne 0 ]
then
echo "There were errors while linting the files, please see above."
exit 1
fi
fi
echo "No errors - committing"