-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-commit
executable file
·58 lines (49 loc) · 1.57 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
#!/usr/bin/env bash
# Hook that checks PHP syntax
# Where are we?
path=$(pwd)
[ ! -d $path/node_modules/.bin ] && exit 1
[ ! -f $path/node_modules/.bin/eslint ] && exit 1
[ ! -f $path/node_modules/.bin/stylelint ] && exit 1
# Override IFS so that spaces do not count as delimiters
old_ifs=$IFS
IFS=$'\n'
echo "* hook: `basename $0`: check file syntax"
result=0
files=$(git status --porcelain | grep -E '\.(php|ctp|js[x]?|css)$' |grep -E "^ ?[MAC]" | awk '{ print $2 }')
for file in $files; do
case ${file##*.} in
php|ctp)
php -l $file
#[[ $? -eq 0 ]] && vendors/cakephp/cakephp/lib/Cake/Console/cake -app /srv/tom/web/app/ test --quiet $file
;;
js|jsx)
FOUND=0
while read l; do
if [[ $l =~ ^[^#] ]]; then
if [[ $(find $path/$l -name $file 2>&1 >/dev/null) ]]; then
FOUND=1
fi
fi
done < ./.eslintignore
[[ $FOUND ]] && continue
$path/node_modules/.bin/eslint $file
;;
#js)
#if [[ $file == build/src/* ]]; then
#$path/node_modules/.bin/eslint $file
#else
#node --check $file && echo $file : no errors
#fi
#;;
#jsx)
#$path/node_modules/.bin/eslint $file
#;;
css)
$path/node_modules/.bin/stylelint $file
#csslint --format=compact --warnings=false $file
;;
esac
result=$((result+=$?))
done
exit $result