Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Enforce go import order via gci linter #5592

Merged
merged 1 commit into from
Nov 8, 2021

Conversation

sbueringer
Copy link
Member

@sbueringer sbueringer commented Nov 5, 2021

Signed-off-by: Stefan Büringer buringerst@vmware.com

What this PR does / why we need it:
The GCI linter is essentially an improved (imho) version of goimports, which is also compatible with goimports, i.e. gci results in an import format which is compatible to what goimports enforces. (just a bit more strict)

With the configuration in this PR it sorts the imports in this order: (we could merge the second and third block if we want)

<go-sdk-imports>

<external-imports>

<imports from the current repo>

I think this would help reviewers and contributors by just enforcing the right import order this way. gci supports make lint-fix so nobody has to sort the imports manually after e.g. Intellij added them arbitrarily.

The current situation where we are not linting it automatically but manually on PRs does not seem like an ideal situation and requires additional effort from reviewers and contributors.

P.S. The changes in this PR are a result of the changes in the golang-ci config + running make lint-fix.

xref: #5585 (comment)

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 5, 2021
@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Nov 5, 2021
@sbueringer sbueringer changed the title [WIP] ✨ enable gci-linter ✨ Enforce go import order via gci linter Nov 5, 2021
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 5, 2021
@sbueringer
Copy link
Member Author

/cc @stmcginnis (next try :))

Copy link
Contributor

@killianmuldoon killianmuldoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

+/- a question on kubebuilder tags - are they just artefacts from the creation process?

api/v1alpha3/suite_test.go Show resolved Hide resolved
bootstrap/kubeadm/api/v1alpha3/suite_test.go Show resolved Hide resolved
bootstrap/kubeadm/main.go Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 5, 2021
@killianmuldoon
Copy link
Contributor

Thanks for this! Definitely going to be a big help on PRs 😄

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 8, 2021
.golangci.yml Outdated
Comment on lines 46 to 47
gci:
local-prefixes: sigs.k8s.io/cluster-api
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use no local prefixes? Most folks out there with goimports won't necessarily make use of it and we can reduce some friction here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 8, 2021
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 8, 2021
Signed-off-by: Stefan Büringer buringerst@vmware.com
Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 8, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vincepri

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 8, 2021
@k8s-ci-robot k8s-ci-robot merged commit cd541a0 into kubernetes-sigs:main Nov 8, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.1 milestone Nov 8, 2021
@sbueringer sbueringer deleted the pr-enable-gci-linter branch November 8, 2021 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants