1
0
mirror of https://github.com/openshift/installer.git synced 2026-02-05 06:46:36 +01:00

tooling: add gci tool to standardize import order

The imports are ordered in 4 sections:
 - standard lib
 - default imports
 - prefix(github.com/openshift)
 - blank imports (_ <import_path>)
This commit is contained in:
Rafael Fonseca
2022-12-13 10:21:51 +01:00
parent 780b29adbe
commit 6039d415ec
3 changed files with 16 additions and 7 deletions

View File

@@ -57,6 +57,13 @@ The coding style suggested by the Golang community is used in installer. See the
Terraform has similar standards, and you can run `terraform fmt` to rewrite Terraform files to the canonical format.
### Import order
The Golang import statements are organized into 4 sections: standard, default, prefix("github.com/openshift"), and blank imports with the [gci tool][gci-tool]. To automatically sort the imports run:
```sh
hack/go-fmt.sh .
```
## Commit Message Format
We follow a rough convention for commit messages that is designed to answer two
@@ -95,6 +102,7 @@ Some unit tests use mocks that are generated with gomock. If the underlying inte
hack/go-genmock.sh
```
[gci-tool]: https://github.com/daixiang0/gci
[golang-style]: https://github.com/golang/go/wiki/CodeReviewComments
[new-issue]: https://github.com/openshift/installer/issues/new
[podman-install]: https://podman.io/getting-started/installation

View File

@@ -1,7 +1,9 @@
#!/bin/sh
if [ "$IS_CONTAINER" != "" ]; then
gci_repo=github.com/daixiang0/gci
for TARGET in "${@}"; do
find "${TARGET}" -name '*.go' ! -path '*/vendor/*' ! -path '*/.build/*' -exec gofmt -s -w {} \+
find "${TARGET}" -name '*.go' ! -path '*/vendor/*' ! -path '*/.build/*' -exec go run "$gci_repo" write -s standard -s default -s "prefix(github.com/openshift)" -s blank --skip-generated {} \+
done
git diff --exit-code
else

View File

@@ -6,13 +6,12 @@
package tools
import (
// dependency of hack/go-lint.sh
_ "golang.org/x/lint"
// dependency of generating CRD for install-config
_ "sigs.k8s.io/controller-tools/cmd/controller-gen"
import ( // dependency of hack/go-fmt.sh
_ "github.com/daixiang0/gci"
// used to generate mocks
_ "github.com/golang/mock/mockgen"
// dependency of hack/go-lint.sh
_ "golang.org/x/lint"
// dependency of generating CRD for install-config
_ "sigs.k8s.io/controller-tools/cmd/controller-gen"
)