From cabeb8b530211b0ba65e0da626e7ffad7f85d489 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 19 Dec 2023 11:52:26 -0800 Subject: [PATCH 1/2] Use gofmt to format and lint --- Makefile | 4 ++-- scripts/check_gofmt.sh | 16 ---------------- scripts/gofmt.sh | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 18 deletions(-) delete mode 100755 scripts/check_gofmt.sh create mode 100755 scripts/gofmt.sh diff --git a/Makefile b/Makefile index cb4d1e837f..f5628f4487 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ check-api-clients: go run scripts/check_api_clients/main.go check-gofmt: - scripts/check_gofmt.sh + scripts/gofmt.sh check lint: staticcheck @@ -39,7 +39,7 @@ update-version: $(MAKE) normalize-imports codegen-format: normalize-imports - go fmt ./... + scripts/gofmt.sh go install golang.org/x/tools/cmd/goimports@latest && goimports -w example/generated_examples_test.go CURRENT_MAJOR_VERSION := $(shell cat VERSION | sed 's/\..*//') diff --git a/scripts/check_gofmt.sh b/scripts/check_gofmt.sh deleted file mode 100755 index 4113d65fac..0000000000 --- a/scripts/check_gofmt.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -find_files() { - find . -not \( \ - \( \ - -name 'vendor' \ - \) -prune \ - \) -name '*.go' -} - -bad_files=$(find_files | xargs gofmt -s -l) -if [[ -n "${bad_files}" ]]; then - echo "!!! gofmt -s needs to be run on the following files: " - echo "${bad_files}" - exit 1 -fi diff --git a/scripts/gofmt.sh b/scripts/gofmt.sh new file mode 100755 index 0000000000..2a8466ee70 --- /dev/null +++ b/scripts/gofmt.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +find_files() { + find . -name '*.go' -not -path "./vendor/*" -not -path "./.git/*" +} + +bad_files=$(find_files | xargs gofmt -s -l) + +# if first argument is check +if [[ "$1" == "check" ]]; then + if [[ -n "${bad_files}" ]]; then + echo "!!! gofmt -s needs to be run on the following files: " + echo "${bad_files}" + exit 1 + fi +fi + +for file in ${bad_files}; do + gofmt -s -w "${file}" +done +exit 0 From 23d2b27e6706e9c2065fbde4a7a9af6e09d35668 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Tue, 19 Dec 2023 11:55:30 -0800 Subject: [PATCH 2/2] comment --- scripts/gofmt.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/gofmt.sh b/scripts/gofmt.sh index 2a8466ee70..0969ddd51c 100755 --- a/scripts/gofmt.sh +++ b/scripts/gofmt.sh @@ -6,7 +6,6 @@ find_files() { bad_files=$(find_files | xargs gofmt -s -l) -# if first argument is check if [[ "$1" == "check" ]]; then if [[ -n "${bad_files}" ]]; then echo "!!! gofmt -s needs to be run on the following files: "