Skip to content

Commit

Permalink
Adding verify gofmt script
Browse files Browse the repository at this point in the history
  • Loading branch information
Uday Ruddarraju committed Feb 5, 2019
1 parent 735e963 commit c92e0f7
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions hack/verify-gofmt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail

ROOT=$(dirname "${BASH_SOURCE}")/..

GO_VERSION=($(go version))

if [[ -z $(echo "${GO_VERSION[2]}" | grep -E 'go1.9|go1.10|go1.11') ]]; then
echo "Unknown go version '${GO_VERSION}', skipping gofmt."
exit 0
fi

cd "${ROOT}"

find_files() {
find . -not \( \
\( \
-wholename './output' \
-o -wholename './_output' \
-o -wholename './release' \
-o -wholename './target' \
-o -wholename '*/third_party/*' \
-o -wholename '*/Godeps/*' \
-o -wholename '*/vendor/*' \
\) -prune \
\) -name '*.go'
}

GOFMT="gofmt -s -w"
bad_files=$(find_files | xargs $GOFMT -l)
if [[ -n "${bad_files}" ]]; then
echo "!!! '$GOFMT' needs to be run on the following files: "
echo "${bad_files}"
exit 1
fi

GOFMT="gofmt -s"
bad_files=$(find_files | xargs $GOFMT -l)
if [[ -n "${bad_files}" ]]; then
echo "!!! '$GOFMT' needs to be run on the following files: "
echo "${bad_files}"
exit 1
fi

0 comments on commit c92e0f7

Please sign in to comment.