Merge pull request #15485 from HanningLin/verify-goimport

Add verify-goimport to verify all import items are well sorted
This commit is contained in:
Marek Siarkowicz 2023-03-16 12:06:00 +01:00 committed by GitHub
commit f3587be6cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -45,7 +45,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-shellws verify-proto-annotations verify-genproto verify-goimport
fix: fix-bom fix-lint
./scripts/fix.sh
@ -109,6 +109,10 @@ verify-proto-annotations:
verify-genproto:
PASSES="genproto" ./scripts/test.sh
.PHONY: verify-goimport
verify-goimport:
PASSES="goimport" ./scripts/test.sh
# Failpoints
GOFAIL_VERSION = $(shell cd tools/mod && go list -m -f {{.Version}} go.etcd.io/gofail)

View File

@ -632,6 +632,21 @@ function genproto_pass {
"${ETCD_ROOT_DIR}/scripts/verify_genproto.sh"
}
function goimport_for_module {
GOFILES=$(run go list --f "{{with \$d:=.}}{{range .GoFiles}}{{\$d.Dir}}/{{.}}{{\"\n\"}}{{end}}{{end}}" ./...)
TESTGOFILES=$(run go list --f "{{with \$d:=.}}{{range .TestGoFiles}}{{\$d.Dir}}/{{.}}{{\"\n\"}}{{end}}{{end}}" ./...)
cd "${ETCD_ROOT_DIR}/tools/mod"
FILESNEEDSFIX=$(echo "${GOFILES}" "${TESTGOFILES}" | grep -v '.gw.go' | grep -v '.pb.go' | xargs -n 100 go run golang.org/x/tools/cmd/goimports -l -local go.etcd.io)
if [ -n "$FILESNEEDSFIX" ]; then
log_error -e "the following files are not sync with 'goimports'. run 'make fix'\\n$FILESNEEDSFIX"
return 255
fi
}
function goimport_pass {
run_for_modules goimport_for_module
}
########### MAIN ###############################################################
function run_pass {