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
x/tools/cmd/goimports: ability to disable pkg renaming #23004
Comments
No, I don't want any flags. People run this from their editors more than they do by hand. There's no place to put flags. Also, the whole point of things like gofmt or goimports is to have conventions that everybody uses, even if they don't all 100% agree on them. Adding flags for people's preferences seems antithetical to the spirit of such tools. |
@bradfitz good point about going against the spirit of such tools and flags just add more knobs that pollute the experience. Totally agree. My point is I don't like auto pkg renaming enough to post this issue and fork my own version to disable it :) perhaps then we could add to imports.Options{} to disable renaming, and export |
Or you could just fork goimports if you don't want to use goimports. :) Why complicate the code base for everybody else, just for one user who wants to be different? If it's just for one user, that's too much complication and maintenance cost. So whether it's 1 person, 100% of people, or anywhere in between, we shouldn't add options. |
That's not necessarily true.
Then why does Edit: Edit 2: Actually, reading through |
gofmt can't make mistakes and can't be slow. goimports can. I wrote it for myself on a long flight and started with it out-of-tree. It was at https://github.com/bradfitz/goimports and then we moved it to x/tools at some point. By having a different binary name, you opt-in to the potential mistakes and slowness. Perhaps it could be part of gofmt, but then it'd need more flags. It seems fine being a separate binary. But that doesn't mean we want to start adding lots of options, just like we don't want gofmt to have lots of options. |
I think this was thoroughly covered. Closing. |
go version go1.9.2 darwin/amd64 and golang.org/x/tools/cmd/goimports @ 0444735
For packages that manage versioning through import paths, such as
"upper.io/db.v3"
or"google.golang.org/api/youtube/v3"
goimports will import these packages as:although it may be a useful hint to readers to see the explicit package name for the path, my preference is to use package renaming only when I'm actually renaming a package, and I tend to understand the packages Im using and their name as
db
oryoutube
.I've determined
findImport()
in https://github.com/golang/tools/blob/master/imports/fix.go#L734 to be the function that provides a rename functionality, later set here: https://github.com/golang/tools/blob/master/imports/fix.go#L258-L260Is there any interest to have the ability for the
goimports
cli to have a flag-norename
that will turn off automatic package renames on import as described above? if so, I'm happy to work on a submission. I understand this is only an aesthetic suggestion and I've already forked the project for my own purposes, but I know others on my team felt similarly so I'm seeing if we can add this as a dedicated option.thanks.
The text was updated successfully, but these errors were encountered: