Skip to content

Add import alias linting and standardize API imports#2142

Open
IrvingMg wants to merge 1 commit intoshipwright-io:mainfrom
IrvingMg:standardize-go-import-aliases
Open

Add import alias linting and standardize API imports#2142
IrvingMg wants to merge 1 commit intoshipwright-io:mainfrom
IrvingMg:standardize-go-import-aliases

Conversation

@IrvingMg
Copy link
Copy Markdown
Member

Changes

Standardize Go import aliases and enforce them using golangci-lint:

  • Add the importas linter to enforce alias naming (buildapi, buildapialpha, pipelineapi)
  • Add the gci formatter to enforce import grouping (stdlib, external, internal)
  • Rename all non-generated imports to align with the new aliases

Related Issue

Fixes #1485

Type of PR

/kind cleanup

Submitter Checklist

  • Includes tests if functionality changed/was added
  • Includes docs if changes are user-facing
  • Kind label has been set
  • Release notes block has been filled in, or marked NONE

See the contributor guide
for details on coding conventions, github and prow interactions, and the code review process.

Release Notes

NONE

@openshift-ci openshift-ci bot added release-note-none Label for when a PR does not need a release note kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Mar 24, 2026
@openshift-ci openshift-ci bot requested review from HeavyWombat and rxinui March 24, 2026 15:35
@pull-request-size pull-request-size bot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Mar 24, 2026
Signed-off-by: Irving Mondragón <mirvingr@gmail.com>
@IrvingMg IrvingMg force-pushed the standardize-go-import-aliases branch from e64b593 to 5f834be Compare March 24, 2026 15:41
@IrvingMg
Copy link
Copy Markdown
Member Author

@shipwright-io/contributors PTAL

Copy link
Copy Markdown
Member

@adambkaplan adambkaplan left a comment

Choose a reason for hiding this comment

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

/approve

Thanks! This will help us a lot with code consistency. I think we had tried something in the past with a different tool, however it wasn't integrated with golangci-lint and thus wasn't enforced.

My suggestions here are opinions and IMO shouldn't block merge/approval. I think we should have a time-scoped discussion (1 week, maximum) on the rules we want for import ordering and aliases. Otherwise this sort of exercise becomes a "paint the bikeshed" ordeal.

importas:
alias:
- pkg: github.com/shipwright-io/build/pkg/apis/build/v1beta1
alias: buildapi
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
alias: buildapi
alias: buildv1beta1

Copy link
Copy Markdown
Member

@SaschaSchwarze0 SaschaSchwarze0 Mar 30, 2026

Choose a reason for hiding this comment

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

-1

The idea of using buildapi / pipelineapi is that when you upgrade to a new version, you only change the import and potentially breaking changes. If the import alias also changes, then you have a lot other changes in code and cannot see the trees in the forest when you review this.

- pkg: github.com/shipwright-io/build/pkg/apis/build/v1beta1
alias: buildapi
- pkg: github.com/shipwright-io/build/pkg/apis/build/v1alpha1
alias: buildapialpha
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
alias: buildapialpha
alias: buildv1alpha1

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm not sure about including the version number. As @SaschaSchwarze0 mentioned, the goal is to reduce noise when API upgrades happen. buildapi should refer to the main API version.But maybe we could rename buildapialpha to something like buildapiexperimental (probably something shorter). WDYT?

- pkg: github.com/shipwright-io/build/pkg/apis/build/v1alpha1
alias: buildapialpha
- pkg: github.com/tektoncd/pipeline/pkg/apis/pipeline/v1
alias: pipelineapi
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
alias: pipelineapi
alias: pipelinev1

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Same discussion as in #2142 (comment)

Comment on lines +14 to +16
- standard
- default
- prefix(github.com/shipwright-io/build)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a good start - I have my own preferences wrt import ordering, however I don't want to block this PR on a never-ending bikeshed discussion.

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Mar 30, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adambkaplan

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

The pull request process is described here

Details 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

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 30, 2026
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. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. release-note-none Label for when a PR does not need a release note size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[FEATURE] Revisit Go imports

4 participants