change govet to prompt for each package similar to staticcheck

Signed-off-by: deepthi <deepthi@planetscale.com>
This commit is contained in:
deepthi 2019-04-26 09:42:03 -07:00
Родитель 696322b5f4
Коммит e83ccd1fc5
2 изменённых файлов: 57 добавлений и 1 удалений

Просмотреть файл

@ -24,15 +24,70 @@ if [ -z "$GOPATH" ]; then
fi
# This script does not handle file names that contain spaces.
gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '^go/.*\.go$')
gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '^go/.*\.go$' | grep -v '^go/vt/proto/' | grep -v 'go/vt/sqlparser/sql.go')
if [ "$gofiles" = "" ]; then
exit 0
fi
# xargs -n1 because dirname on MacOS does not support multiple arguments.
gopackages=$(echo $gofiles | xargs -n1 dirname | sort -u)
warnings=
# If any checks are found to be useless, they can be disabled here.
# See the output of "go doc cmd/vet" for a list of flags.
vetflags=""
# Run on one package at a time
gopackages_with_warnings=()
for gopackage in $gopackages
do
warningcount="$(go vet $vetflags "vitess.io/vitess/$gopackage" 2>&1 | grep -v ^# | wc -l)"
if [ "$warningcount" -gt "0" ]; then
warnings=YES
echo "$warningcount reports for:"
echo "go vet $vetflags vitess.io/vitess/$gopackage"
gopackages_with_warnings+=($gopackage)
fi
done
[ -z "$warnings" ] && exit 0
# git doesn't give us access to user input, so let's steal it.
exec < /dev/tty
if [[ $? -eq 0 ]]; then
# interactive shell. Prompt the user.
echo
echo "Suggestions from the go vet program were found."
echo "They're not enforced, but we're pausing to let you know"
echo "before they get clobbered in the scrollback buffer."
echo
read -r -p 'Press enter to cancel, "s" to step through the warnings or type "ack" to continue: '
if [ "$REPLY" = "ack" ]; then
exit 0
fi
if [ "$REPLY" = "s" ]; then
first_file="true"
for gopackage in "${gopackages_with_warnings[@]}"
do
echo
if [ "$first_file" != "true" ]; then
echo "Press enter to show the warnings for the next file."
read
fi
go vet $vetflags "vitess.io/vitess/$gopackage"
first_file="false"
done
fi
else
# non-interactive shell (e.g. called from Eclipse). Just display the warnings.
for gopackage in "${gopackages_with_warnings[@]}"
do
go vet $vetflags "vitess.io/vitess/$gopackage"
done
fi
exit 1
if ! go vet $vetflags $(echo $gofiles) 2>&1; then
echo ""
echo "Please fix the go vet warnings above. To disable certain checks, change vetflags in misc/git/hooks/govet."

Просмотреть файл

@ -18,6 +18,7 @@ gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '^go/.*\.go$' |
if [ "$gofiles" = "" ]; then
exit 0
fi
# xargs -n1 because dirname on MacOS does not support multiple arguments.
gopackages=$(echo $gofiles | xargs -n1 dirname | sort -u)