forked from bloomberg/phabricator-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphlint.sh
executable file
·130 lines (116 loc) · 4.17 KB
/
phlint.sh
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# comment on reviews which we find linter errors for
# exit with error message if anything returns error status
trap 'echo FAILED; exit 1' ERR
set -e
#set -x
# need to specify revision and connection parameters on the command-line
#
# e.g.
# ./phlint -r 4006 --uri http://127.0.0.1
#
revision="$1"
shift
prev_dir=$(pwd)
temp_dir=$(mktemp -d)
left_files_lint=$(mktemp)
right_files_lint=$(mktemp)
message_file=$(mktemp)
arcyon get-diff --format-files $temp_dir -r ${revision} "$@"
cd $temp_dir
cd left
set +e
trap - ERR
jshint . | sed '/^$/d' > $left_files_lint
cppcheck -q . 2>> $left_files_lint
pyflakes . >> $left_files_lint
trap 'echo FAILED; exit 1' ERR
set -e
cd ..
cd right
set +e
trap - ERR
jshint . | sed '/^$/d' > $right_files_lint
cppcheck -q . 2>> $right_files_lint
pyflakes . >> $right_files_lint
trap 'echo FAILED; exit 1' ERR
set -e
cd ..
cd ${prev_dir}
# don't output the first 3 lines of the diff, they're the header and not relevant
#
# e.g.
# --- /tmp/tmp.Mq5cmFpk20 2013-11-19 14:08:41.868364952 +0000
# +++ /tmp/tmp.RS4zJ0RPkY 2013-11-19 14:08:41.876364879 +0000
# @@ -0,0 +1 @@
#
result=$(diff -U 1000 --suppress-common-lines $left_files_lint $right_files_lint | tail -n +4)
left_count=$(cat ${left_files_lint}| wc -l )
right_count=$(cat ${right_files_lint} | wc -l )
new_or_moved_errors=$(echo "${result}" | sed -n '/^\+/p')
no_errors=0
if [ "${right_count}" -eq 0 ]; then
if [ "${left_count}" -eq 0 ]; then
no_errors=1
fi
fi
if [ "${no_errors}" -eq 1 ]; then
echo verdict: **NO ERRORS BEFORE. NO ERRORS NOW. GOOD.** >> ${message_file}
else
if [ ! -z "${new_or_moved_errors}" ]; then
echo first 10 moved or new error messages: > ${message_file}
echo >> ${message_file}
echo '``` lang=text, counterexample' >> ${message_file}
echo "${new_or_moved_errors}" | sed 's/^.//' | head >> ${message_file}
echo '```' >> ${message_file}
else
echo first 10 error messages: > ${message_file}
echo >> ${message_file}
echo '``` lang=text, counterexample' >> ${message_file}
echo cat "${right_files_lint}" | sed 's/^.//' | head >> ${message_file}
echo '```' >> ${message_file}
fi
echo >> ${message_file}
echo summary: >> ${message_file}
echo >> ${message_file}
echo '| number of error messages |' >> ${message_file}
echo '| ---- |' >> ${message_file}
echo '| before changes | ' ${left_count} ' |' >> ${message_file}
echo '| after changes | ' ${right_count} ' |' >> ${message_file}
echo >> ${message_file}
if [ "${right_count}" -eq 0 ]; then
echo verdict: **NO ERROR NOW. GOOD.** >> ${message_file}
elif [ "${left_count}" -eq "${right_count}" ]; then
echo verdict: **NOT WORSE. NOT BETTER.** >> ${message_file}
elif [ "${left_count}" -gt "${right_count}" ]; then
echo verdict: **IMPROVEMENT. GOOD.** >> ${message_file}
elif [ "${left_count}" -lt "${right_count}" ]; then
echo verdict: **MAKE LESS ERROR NOT MOAR!** >> ${message_file}
fi
cat ${message_file}
read -p "Please hit 'y' to continue, any other to abort: "
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
echo aborted.
exit 1
fi
arcyon comment ${revision} --message-file "${message_file}" "$@"
fi
rm -rf $temp_dir
rm $left_files_lint
rm $right_files_lint
rm $message_file
# -----------------------------------------------------------------------------
# Copyright (C) 2013-2014 Bloomberg Finance L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------ END-OF-FILE ----------------------------------