build icon indicating copy to clipboard operation
build copied to clipboard

[FEATURE] Revisit Go imports

Open SaschaSchwarze0 opened this issue 1 year ago • 3 comments

Is there an existing feature request for this?

  • [X] I have searched the existing feature requests

Is your feature request related to a problem or use-case? Please describe.

The imports we go in our Go sources are not consistent and not ideal for code reviews.

In particular, when reviewing a PR like this, it would be helpful if import changes come without alias changes.

Describe the solution that you would like.

In the community meeting, we concluded that we will use names like buildapi or pipelineapi going forward for API imports to make them independent of the imported version. Exceptions would still be allowed when we import more than one version (like we do in triggers for Tekton as we need v1 to work with Pipelines but also v1beta1 for Runs).

In addition, Matthias suggested to evaluate if a tool exists that verifies that imports are as expected, and can maybe autofix this.

Describe alternatives you have considered.

No response

Anything else?

No response

SaschaSchwarze0 avatar Feb 05 '24 14:02 SaschaSchwarze0

We can consider to use goimports if its features would be helpful for our ideas. Need to verify the feature set first.

HeavyWombat avatar Feb 05 '24 15:02 HeavyWombat

We can consider to use goimports if its features would be helpful for our ideas. Need to verify the feature set first.

Checked the tool. It can do things like reordering imports but I found no way to rename imports in the way we want it.

SaschaSchwarze0 avatar Nov 16 '24 19:11 SaschaSchwarze0

From refinement - adding to backlog as having a community standard on import ordering would be beneficial.

Enforcing a standard on import namings is a lot more challenging - per @SaschaSchwarze0 no tooling exists yet to enforce a pattern. goimports can at least enforce standards on import ordering, and we can enable it with golangci-lint.

adambkaplan avatar Dec 12 '24 15:12 adambkaplan