mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 09:52:49 +00:00
cleanup verify-gofmt.sh
- clarify comments - simplify to just use gofmt from path - setup go env instead of just verify go version
This commit is contained in:
parent
e55e41b86a
commit
b0144538da
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user