-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
proposal: Remove redundant package aliases from import blocks #296
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I think this is kind of a deal breaker - it would slow down formatting significantly. Right now the formatting is syntax-based alone, it doesn't load type information or any package information. All it looks at is what the main module path is, for the sake of grouping imports. gofmt has the same limitation, also for the sake of performance.
For example, I regularly run
gofumpt -l -w .
on large projects, so if that has to load every package in a named import for every file, that would likely mean hundreds of calls togo list
, as well as orders of magnitude more opened files and syscalls.That said, I agree that this is a good rule to enforce. Perhaps it should go into a tool that already loads type information - the two obvious candidates that come to mind are gopls (since it already has an "organize imports" code action akin to the old goimports) and staticcheck (since it has similar rules already like https://staticcheck.dev/docs/checks#ST1019).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right: it does seem to slow things down quite a lot.
The monorepo I work in has around 1.1m lines of Go. Before the change, it took ~9s to act on the whole codebase; after, it takes ~27s. It's a pity: I try to be in the business of making things faster, not slower.
I'll see about contributing a new check to staticcheck.
Thanks for the quick response!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should note that you could make this faster in gofumpt by e.g. caching the calls to go/packages, or calling it upfront on all packages to format to reduce the number of execs to
go list
. But I still think that would be a significant slow-down, and going against the gofmt philosophy of formatting based on syntax alone.For instance, we aim to provide a Go API compatible with https://pkg.go.dev/go/format. Such an API is self-contained, it doesn't require type information nor the ability to call
go list
.