-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
internal/imports: force to repair imports group regardless of how the… #150
base: master
Are you sure you want to change the base?
Conversation
…y were originally grouped
This PR (HEAD: 21a9fe9) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/tools/+/193499 to see it. Tip: You can toggle comments from me using the |
Message from Gobot Gobot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/193499. |
Message from Heschi Kreinick: Patch Set 1: I think this should be discussed on the issue. My feeling is that if the functionality is reliable it should probably be on by default, and if it's not reliable it shouldn't be merged at all. But others may have other opinions. I haven't looked at the code yet, but I see that it has no tests. We definitely need some before this can be merged. In particular, whatever triggered the rollback in https://golang.org/cl/144339 should be covered. Please don’t reply on this GitHub thread. Visit golang.org/cl/193499. |
Message from Brad Fitzpatrick: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/193499. |
Is this PR still being worked on? This functionality would be very useful for us. |
Hey, I'm also interesting in this PR. |
@harveyxia @SVilgelm |
as a temporary solution, you can use
details: https://github.com/kamilsk/go-tools/releases/tag/goimports. |
I think this change would be really helpful, imports get messy quickly, specially when you let IDEs do auto imports. |
Message from Go Bot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/193499. |
Is this PR dead? |
Can we bump this PR to be merged? |
What this PR does
Add a new flag
repair-group
. If true, forcing to repair imports group regardless of how they were originally groupedFixed golang/go#20818
Why
What goimports does not do
example:
The imports will keep intact because
"testing"
and"context"
are considered in two different sections.Manually correct
If we delete the blank line, goimports will re-sort imports correctly.
input:
after formatting:
Root case
When goimports formats the imports, it puts imports into different sections by successive lines, and sorts them in each section. It turns out that sorting will only happens in the same section.
In order to solve this problem, we only need to consider all imports in one group regardless of how they were originally grouped
Result of use repair-group
input:
runs
output: