calico icon indicating copy to clipboard operation
calico copied to clipboard

Formatting code with gofmt

Open cuishuang opened this issue 1 year ago • 6 comments

Description

Formatting code with gofmt

Related issues/PRs

Todos

  • [ ] Tests
  • [ ] Documentation
  • [ ] Release note

Release Note

Formatting code with gofmt

Reminder for the reviewer

Make sure that this PR has the correct labels and milestone set.

Every PR needs one docs-* label.

  • docs-pr-required: This change requires a change to the documentation that has not been completed yet.
  • docs-completed: This change has all necessary documentation completed.
  • docs-not-required: This change has no user-facing impact and requires no docs.

Every PR needs one release-note-* label.

  • release-note-required: This PR has user-facing changes. Most PRs should have this label.
  • release-note-not-required: This PR has no user-facing changes.

Other optional labels:

  • cherry-pick-candidate: This PR should be cherry-picked to an earlier release. For bug fixes only.
  • needs-operator-pr: This PR is related to install and requires a corresponding change to the operator.

cuishuang avatar Sep 25 '24 08:09 cuishuang

@cuishuang We already have a mechanism for formatting in this repo, with make fix. It uses goimports, and I've just run it locally to see if it makes the same changes as in this PR, and it doesn't.

Your changes look good (and I also see that gopls recommends them), but instead of just committing them we need to work out why our make fix and goimports usage doesn't make the same changes. I'm wondering if we are using an excessively old versoin of goimports in our go-build container.

nelljerram avatar Sep 25 '24 09:09 nelljerram

It seems we're already using the latest goimports (v0.25.0), so it's puzzling why that isn't already making these changes.

nelljerram avatar Sep 25 '24 09:09 nelljerram

It seems we're already using the latest goimports (v0.25.0), so it's puzzling why that isn't already making these changes.

Yes, it is confusing. goimports is a stricter way of formatting than gofmt

cuishuang avatar Sep 25 '24 09:09 cuishuang

@caseydavenport Would you happen to know why goimports doesn't make these changes for us?

nelljerram avatar Sep 25 '24 09:09 nelljerram

I also ran goimports locally and it did not produce these changes. I am not sure why. The changes look reasonable to me, but I am a bit confused by why goimports doesn't do it for me.

caseydavenport avatar Oct 02 '24 16:10 caseydavenport

Looks like @cuishuang ran gofmt -s for "simplify". goimports doesn't support -s so we don't use it.

fasaxc avatar Oct 17 '24 14:10 fasaxc

/sem-approve

fasaxc avatar Oct 29 '24 10:10 fasaxc