-
-
Notifications
You must be signed in to change notification settings - Fork 113
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
gofumpt and gofumports regroup imports that gofmt/goimports leave alone #22
Comments
This is because it assumes imports with no domain extension belong in the standard library. I'm pretty sure this is the same rule that the go tool applies; any import with no TLD might be broken at any point. |
Citation? |
Uh, I'm not sure! I'll get back to you on this :) |
So it turns out there's no official docs on this. I only knew this from interactions with Bryan on GitHub and Slack. I've opened golang/go#32819. I'll keep this issue open for now, but I'm not sure if this can be done any other way in the future. Hard-coding a list of |
I suggest doing whatever gofmt/goimports do today. FWIW we've used this scheme for many years and have had zero tooling problems due to it. We might change our paths when we move to modules, but for now I see no point in making up faking TLD-based import paths for packages that aren't publicly accessible on the internet anyway. |
I am indeed following what
You're only seeing problems here because |
I see. I didn't realize that gofumpt tries to do extra stuff with imports since that wasn't in the list of features. |
You're right! I must have forgotten to add that bit. |
Anyway, I think that the fix here is indeed to know what is and is not in std rather than guess based on this heuristic. But even without doing that, ISTM that if I provide gofumports with |
I just don't think that's practical in the long term. Even if I take the time to keep the list up to date with time, what if a user has a version of the tool that's too old or too new? It could lead to surprising behavior. In contrast, this heuristic is simple and shouldn't surprise anyone, if the doc issue above is fixed. If anyone wants to stick to these grey-area import paths for the time being, that's fine; they know what they are doing.
That seems reasonable. Just bear in mind that only |
The upstream issue was labeled NeedsFix, so it looks like my thinking was correct. I'll close this as "works as intended" for now. Thanks for bringing it up though, as the documentation was lacking in both this repo and upstream. |
FYI, see #187 (comment); I'm currently thinking we could do better for everyone by looking at the main module's path. |
Add the feature, test it, and document it in the README. It's enough to mention it in the FAQ, as I expect that most users will never run into this edge case. And those few that may run into it will hopefully never need to know how it works or why. Note that this adds a new option to pass the info from go.mod, much like LangVersion already did. Fixes #22. Fixes #117. Fixes #120. Fixes #187.
Add the feature, test it, and document it in the README. It's enough to mention it in the FAQ, as I expect that most users will never run into this edge case. And those few that may run into it will hopefully never need to know how it works or why. Note that this adds a new option to pass the info from go.mod, much like LangVersion already did. Fixes #22. Fixes #117. Fixes #120. Fixes #187.
Add the feature, test it, and document it in the README. It's enough to mention it in the FAQ, as I expect that most users will never run into this edge case. And those few that may run into it will hopefully never need to know how it works or why. Note that this adds a new option to pass the info from go.mod, much like LangVersion already did. Fixes #22. Fixes #117. Fixes #120. Fixes #187.
When I run gofumpt or gofumports over our code, the diffs are huge because it regroups all the imports. For instance:
This happens with gofumpt and with gofumports executed with
but not with gofmt or goimports executed with
The text was updated successfully, but these errors were encountered: