-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpre-commit
87 lines (52 loc) · 2.22 KB
/
pre-commit
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
#!/bin/bash
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
ROOT_DIR=$(git rev-parse --show-toplevel)
ABS_PATH="{PATH TO BUILD TOOLS}"
JSLINT="$ABS_PATH/JSLint/fulljslint.js"
JSLINT4JAVA="$ABS_PATH/jslint4java/jslint4java-2.0.0/jslint4java-2.0.0.jar"
# The csslint rules to use
# The current selection is based on discussion here: http://mattwilcox.net/archive/entry/id/1054/
CSSLINT_RULES="display-property-grouping,duplicate-properties,empty-rules,known-properties,box-sizing,compatible-vendor-prefixes,gradients,vendor-prefix,import,zero-units,shorthand,important"
CSSLINT_RHINO="$ABS_PATH/csslint/release/csslint-rhino.js"
RHINO_JAR="$ABS_PATH/rhino/rhino1_7R3/js.jar"
PHPPRECOMMIT="$ABS_PATH/php/pre-commit.php"
########################### JS Lint ###########################
JSLINTCMD="${JSLINT4JAVA} --jslint ${JSLINT}"
for file in $(git diff-index --name-only --cached HEAD -- | grep -P '\.((js)|(html)|(json))$'); do
jstest=$(java -jar $JSLINTCMD $file)
if [ -n "$jstest" ] ; then
printf "JS error in $file \n$jstest"
exit 1
fi
done
########################### CSS Lint ###########################
CSSLINTCMD="${RHINO_JAR} $CSSLINT_RHINO --format=text --rules=$CSSLINT_RULES"
for file in $(git diff-index --name-only --cached HEAD -- | grep -P '\.css$'); do
csstest=$(java -jar ${CSSLINTCMD} $file)
if [ -n "$csstest" ] ; then
printf "CSS error in $file \n$csstest"
exit 1
fi
done
########################### XML Lint ###########################
for file in $(git diff-index --name-only --cached HEAD -- | grep -P '\.((xml)|(xsl))$'); do
xmltest=$(xmllint --noout ${file})
if [ $? -gt 0 ] ; then
printf "XML error in $file \n$xmltest"
exit 1
fi
done
########################### PHP Lint ###########################
PHPCMD=$("${PHPPRECOMMIT}")
if [ $? -eq 1 ] ; then
printf "PHP errors\n$PHPCMD"
exit 1
fi
############ ALL GOOD! WELL DONE! GOOD JOB! EXIT ###############
exit 0