reformat with goimports -local#7533
Conversation
The -local flag allows us to separate imports that originate from github.com/containerd/containerd from other imports, making it more clear where various imports come from. Files can be formatted using the following command: goimports -w -local github.com/containerd/containerd To reformat all Go source files (excluding vendor and .pb.go): goimports -w -local github.com/containerd/containerd \ $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "*.pb.go") Signed-off-by: Samuel Karp <[email protected]>
Signed-off-by: Samuel Karp <[email protected]>
thaJeztah
left a comment
There was a problem hiding this comment.
Left comments inline
Some thoughts in general;
- This will be disruptive for some time
- cause quite some merge conflicts on open PRs
- switching between branches (main <--> 1.6 LTS) will require switching tooling settings to use the expected convention
- The linter apparently doesn't do a great job on checking these, and doesn't enforce "3 groups (stdlib, external, local)"
- Perhaps the
gcilinter does handle this? (haven't checked) https://golangci-lint.run/usage/linters/
- Perhaps the
- If we want this format to be enforced, perhaps we need a
make fmttarget, otherwise contributors must typegoimports -w --local github.com/containerd/containerd .(which is a lot to type)
I'm also wondering (if we go ahead with this) would it make sense to change "local" to github.com/containerd/ (all imports from within the containerd org)?
- Packages may move around within the org, and perhaps we want to make that less disruptive
- How should separate modules be treated? e.g. if
github.com/containerd/containerd/apibecomes its own module, is it still "local"? It's in the same repo, but effectively "non-local"
| @@ -25,9 +25,10 @@ import ( | |||
|
|
|||
| "github.com/sirupsen/logrus" | |||
There was a problem hiding this comment.
Looks like this one needs to be together with the one below
| "k8s.io/klog/v2" | ||
|
|
||
| internalapi "github.com/containerd/containerd/integration/cri-api/pkg/apis" | ||
| runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1" |
| internalapi "github.com/containerd/containerd/integration/cri-api/pkg/apis" | ||
|
|
||
| "github.com/containerd/containerd/integration/remote/util" |
| "k8s.io/klog/v2" | ||
|
|
||
| internalapi "github.com/containerd/containerd/integration/cri-api/pkg/apis" | ||
| "k8s.io/component-base/logs/logreduction" |
| internalapi "github.com/containerd/containerd/integration/cri-api/pkg/apis" | ||
|
|
||
| "github.com/containerd/containerd/integration/remote/util" |
|
|
||
| snapshotstore "github.com/containerd/containerd/pkg/cri/store/snapshot" | ||
| ctrdutil "github.com/containerd/containerd/pkg/cri/util" |
There was a problem hiding this comment.
Move these together with the containerd group above
| "github.com/containerd/containerd/version" | ||
|
|
||
| "github.com/containerd/containerd/pkg/cri/constants" |
| "golang.org/x/sys/unix" | ||
|
|
||
| "github.com/containerd/console" |
| "github.com/containerd/containerd/pkg/shutdown" | ||
|
|
||
| api "github.com/containerd/containerd/api/runtime/sandbox/v1" |
| "github.com/containerd/containerd/services" | ||
|
|
||
| api "github.com/containerd/containerd/api/services/sandbox/v1" |
|
Thanks for the thorough review @thaJeztah!
Yep, I want to see what everyone else thinks about this. It'll definitely be disruptive, but I think it makes the imports clearer (and it'll reduce the chance of me/my IDE changing them in other unrelated PRs 😆).
If we're onboard with this change, I think we can do the same thing on the 1.5 and 1.6 branches as well.
My preference would be to do this with
I can do this.
I thought about these too and landed on |
|
This PR is stale because it has been open 90 days with no activity. This PR will be closed in 7 days unless new comments are made or the stale label is removed. |
|
This PR was closed because it has been stalled for 7 days with no activity. |

The -local flag allows us to separate imports that originate from github.com/containerd/containerd from other imports, making it more clear where various imports come from.
Files can be formatted using the following command:
To reformat all Go source files (excluding vendor and .pb.go):