2017-11-10 03:35:02 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
## Only uncomment the below for debugging
|
|
|
|
#set -euxo pipefail
|
|
|
|
|
|
|
|
pushd $PWD/..
|
|
|
|
GO_FILES_EXCLUDING_VENDOR=$(find . -type f -name '*.go' -not -path "./vendor/*")
|
|
|
|
FMT_RESULTS=$(gofmt -l $GO_FILES_EXCLUDING_VENDOR)
|
2017-11-15 01:08:41 +08:00
|
|
|
FMT_RESULTS_COUNT=$(echo $FMT_RESULTS | wc -l) # returns one empty line when everything passes
|
|
|
|
if [ "$FMT_RESULTS_COUNT" -gt 1 ]; then
|
2017-11-10 03:35:02 +08:00
|
|
|
# some files have formatting errors
|
|
|
|
echo "--- gofmt found errors found in the following files:"
|
|
|
|
echo $FMT_RESULTS
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
# no files have formatting errors
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
popd
|