-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/cmd/goimports: better understanding of failure to update imports #28935
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
@theckman - do you think there is a bug here? If so, please can you complete the issue template with a small repro? The output of Else if this is more of a general question, then please can we move this to another forum: https://github.com/golang/go/wiki/Questions? Thanks |
This could be read as a feature request for a verbose flag to goimports. |
It already has one. @theckman, please run goimports -v and attach the results. |
@myitcv it's an internal application, getting a repro ready would require a bit of work. I can maybe focus on that once I've some spare cycles. Sucks because I want to open source it eventually... This is more of a feature request. I don't know if there's a bug present because @josharian there is one, but hopefully its output will be more meaningful to @heschik than it has been to me:
|
Judging from that output, it didn't find a directory on $GOPATH that contained the word "mockaccounts". What directory should it have found the package in? |
@heschik it should be adding the import line |
Yep, that appears to be it. I don't recall ever having had an issue before with the package name not matching the folder name. Especially because I've used things like Have I just been lucky? |
It doesn't need to be an exact match but it does need to contain the package name. go-homedir contains homedir, but mocks/poller/accounts does not contain mockaccounts. (mock/accounts might work today but I wouldn't advise relying on it.) This is WAI. It's not feasible to load the real package name from every directory in $GOPATH. I suppose we could add something to the log like "looking for directory named mockaccounts" but the real matching rules are pretty complicated. |
@heschik where is this documented? Could we re-open this issue and rename it to be an ask for docs? Separate issue? |
I'm not aware of anything that would go into this much detail. File a new issue and ask bradfitz, I guess. |
I'm using
goimports
with thego version go1.11.2 darwin/amd64
toolchain. I've hit a case wheregoimports
isn't adding imports when I'd expect it to, and I'm trying to inspect why that is. I am not using modules, and the project is within myGOPATH
. The import I'm trying to add is also within the GOPATH, and is actually within the same git repo.Without the import added, the build failure (via
go test .
) is:Once I manually add the import the tests pass just fine. I'm trying to understand what's causing
goimports
to be unsure what package to add. I've tried to look for any packages that have functions with similar methods, to no avail.Does anyone know of a good way to figure out why
goimports
isn't adding my import.The text was updated successfully, but these errors were encountered: