diff --git a/hack/verify-gofmt.sh b/hack/verify-gofmt.sh index 03888f09f6c..dc8d3d7bebe 100755 --- a/hack/verify-gofmt.sh +++ b/hack/verify-gofmt.sh @@ -14,10 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -# This script checks whether the source codes need to be formatted or not by -# `gofmt`. We should run `hack/update-gofmt.sh` if actually formats them. +# This script checks whether the source code needs to be formatted or not by +# `gofmt`. Run `hack/update-gofmt.sh` to actually format sources. +# +# Note: gofmt output can change between go versions. +# # Usage: `hack/verify-gofmt.sh`. -# Note: GoFmt apparently is changing @ head... set -o errexit set -o nounset @@ -28,12 +30,7 @@ source "${KUBE_ROOT}/hack/lib/init.sh" cd "${KUBE_ROOT}" -# Prefer bazel's gofmt. -gofmt="external/io_bazel_rules_go_toolchain/bin/gofmt" -if [[ ! -x "${gofmt}" ]]; then - gofmt=$(which gofmt) - kube::golang::verify_go_version -fi +kube::golang::setup_env find_files() { find . -not \( \ @@ -56,7 +53,7 @@ find_files() { # formatting (e.g., a file does not parse correctly). Without "|| true" this # would have led to no useful error message from gofmt, because the script would # have failed before getting to the "echo" in the block below. -diff=$(find_files | xargs "${gofmt}" -d -s 2>&1) || true +diff=$(find_files | xargs gofmt -d -s 2>&1) || true if [[ -n "${diff}" ]]; then echo "${diff}" >&2 echo >&2