Ensure goimports can be fixed individually.

Signed-off-by: James Blair <mail@jamesblair.net>
This commit is contained in:
James Blair 2023-06-16 21:47:46 +12:00
parent 8c483f31ad
commit 2791422f77
No known key found for this signature in database
3 changed files with 33 additions and 12 deletions

View File

@ -65,7 +65,7 @@ fuzz:
verify: verify-gofmt verify-bom verify-lint verify-dep verify-shellcheck verify-goword \
verify-govet verify-license-header verify-receiver-name verify-mod-tidy verify-shellcheck \
verify-shellws verify-proto-annotations verify-genproto verify-goimport verify-yamllint
fix: fix-bom fix-lint fix-yamllint
fix: fix-goimports fix-bom fix-lint fix-yamllint
./scripts/fix.sh
.PHONY: verify-gofmt
@ -132,6 +132,10 @@ verify-genproto:
verify-goimport:
PASSES="goimport" ./scripts/test.sh
.PHONY: fix-goimports
fix-goimports:
./scripts/fix-goimports.sh
.PHONY: verify-yamllint
verify-yamllint:
yamllint --config-file tools/.yamllint .

28
scripts/fix-goimports.sh Executable file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -euo pipefail
source ./scripts/test_lib.sh
ROOTDIR=$(pwd)
# To fix according to newer version of go:
# go get golang.org/dl/gotip
# gotip download
# GO_CMD="gotip"
GO_CMD="go"
ROOTDIR=$(pwd)
function go_imports_fix {
GOFILES=$(run ${GO_CMD} list --f "{{with \$d:=.}}{{range .GoFiles}}{{\$d.Dir}}/{{.}}{{\"\n\"}}{{end}}{{end}}" ./...)
TESTGOFILES=$(run ${GO_CMD} list --f "{{with \$d:=.}}{{range .TestGoFiles}}{{\$d.Dir}}/{{.}}{{\"\n\"}}{{end}}{{end}}" ./...)
cd "${ROOTDIR}/tools/mod"
echo "${GOFILES}" "${TESTGOFILES}" | grep -v '.gw.go' | grep -v '.pb.go' | xargs -n 100 go run golang.org/x/tools/cmd/goimports -w -local go.etcd.io
}
log_callout -e "\\nFixing goimports for you...\n"
run_for_modules go_imports_fix || exit 2
log_success -e "\\nSUCCESS: goimports are fixed :)"

View File

@ -8,8 +8,6 @@ go mod tidy
source ./scripts/test_lib.sh
source ./scripts/updatebom.sh
ROOTDIR=$(pwd)
# To fix according to newer version of go:
# go get golang.org/dl/gotip
# gotip download
@ -31,20 +29,11 @@ function bash_ws_fix {
find ./ -name '*.sh.bak' -print0 | xargs -0 rm
}
function go_imports_fix {
GOFILES=$(run ${GO_CMD} list --f "{{with \$d:=.}}{{range .GoFiles}}{{\$d.Dir}}/{{.}}{{\"\n\"}}{{end}}{{end}}" ./...)
TESTGOFILES=$(run ${GO_CMD} list --f "{{with \$d:=.}}{{range .TestGoFiles}}{{\$d.Dir}}/{{.}}{{\"\n\"}}{{end}}{{end}}" ./...)
cd "${ROOTDIR}/tools/mod"
echo "${GOFILES}" "${TESTGOFILES}" | grep -v '.gw.go' | grep -v '.pb.go' | xargs -n 100 go run golang.org/x/tools/cmd/goimports -w -local go.etcd.io
}
log_callout -e "\\nFixing etcd code for you...\n"
run_for_modules mod_tidy_fix || exit 2
run_for_modules run ${GO_CMD} fmt || exit 2
run_for_module tests bom_fix || exit 2
log_callout "Fixing goimports..."
run_for_modules go_imports_fix || exit 2
bash_ws_fix || exit 2