🌱 add a verify rule for golang files import order (#177)

* 🌱 add a verify rule for golang files import order

This PR uses the [gci tool](https://github.com/daixiang0/gci) to make all go files' import section with a specific order, it will organize import with group with order:
1. standard library modules
2. 3rd party modules
3. modules in OCM org, like the `open-cluster-management.io/api`
4. current project `open-cluster-management.io/ocm` modules

developers can use the `make fmt-imports` to format the import automatically and the `make verify-fmt-imports` to check for any violation.

Signed-off-by: zhujian <jiazhu@redhat.com>

* 🌱 format the go files import

Signed-off-by: zhujian <jiazhu@redhat.com>

---------

Signed-off-by: zhujian <jiazhu@redhat.com>
This commit is contained in:
Jian Zhu
2023-06-12 22:23:04 +08:00
committed by GitHub
parent 3c9bfea949
commit 7332a585c0
266 changed files with 826 additions and 594 deletions

View File

@@ -68,6 +68,21 @@ verify-gocilint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
golangci-lint run --timeout=3m --modules-download-mode vendor ./...
install-golang-gci:
go install github.com/daixiang0/gci@v0.10.1
fmt-imports: install-golang-gci
gci write --skip-generated -s standard -s default -s "prefix(open-cluster-management.io)" -s "prefix(open-cluster-management.io/ocm)" cmd pkg test dependencymagnet
verify-fmt-imports: install-golang-gci
@output=$$(gci diff --skip-generated -s standard -s default -s "prefix(open-cluster-management.io)" -s "prefix(open-cluster-management.io/ocm)" cmd pkg test dependencymagnet); \
if [ -n "$$output" ]; then \
echo "Diff output is not empty: $$output"; \
exit 1; \
else \
echo "Diff output is empty"; \
fi
verify: verify-crds
ensure-operator-sdk: