-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-commit-laravel
executable file
·98 lines (85 loc) · 2.53 KB
/
pre-commit-laravel
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
#!/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
[ ! -d $path/vendor/bin ] && exit 1
[ ! -f $path/vendor/bin/phpcs ] && 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|js[x]?|css)$' |grep -E "^ ?[MAC]" | awk '{ print $2 }')
for file in $files; do
case ${file##*.} in
php)
echo "PHP syntax"
php -l $file
result=$?
if [[ $result -gt 0 ]]; then
exit $result
fi
#echo "Code Sniffer"
#$path/vendor/bin/phpcs $file
#result=$?
#if [[ $result -gt 0 ]]; then
# exit $result
#fi
#echo "PHP mess detector"
#phpmd $file ansi unusedcode
#result=$?
#if [[ $result -gt 0 ]]; then
#exit $result
#fi
#echo "PHP mess detector"
#phpmd $file ansi naming
#result=$?
#if [[ $result -gt 0 ]]; then
#exit $result
#fi
#echo "CPD"
#phpcpd $file
#result=$?
#if [[ $result -gt 0 ]]; then
#exit $result
#fi
;;
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
result=$?
if [[ $result -gt 0 ]]; then
exit $result
fi
;;
#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
result=$?
if [[ $result -gt 0 ]]; then
exit $result
fi
#csslint --format=compact --warnings=false $file
;;
esac
done