-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: cmd/gofmt: organize renamed imports #26846
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
Comments
/cc @griesemer |
This seems like a job for goimports, since gofmt has never split import groups yet goimports does so by design. |
If you have a bunch of related renamings then you may want to see them all together. If you have just a few in a large list of imports, the benefit of sorting them with the normal imports is that when you look for a particular import you only need to consider one list. For example in cmd/go we have variables named 'path' quite a bit, so conventionally the import of "path" comes in as pathpkg. Here's one real import block:
I think it would be inappropriate for gofmt or goimports to force moving the path import into its own section. We intentionally leave this to local custom - gofmt and goimports will never move imports across blank lines in the import block. So if I want path with the others, I can do that, and gofmt/goimports respect that. And if you want all your renamed imports together, you can do that, and gofmt/goimports respect that too. There's not a compelling reason to force everyone onto one side or the other. |
Currently
gofmt
will sort all imports alphabetically, and if you have aliased imports on your imports, this would result to a mixed untidy import.For example, the following import will be sorted alphabetically
which would result to an untidy mix
I proposed that aliased imports to be organized to it's own block, for example
So it would be much cleaner and easily readable.
The text was updated successfully, but these errors were encountered: