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: does not understand identifiers defined by internal test files #29979
Comments
The test script has a typo -- it's running on |
@heschik Thanks, you're right! I'll have to investigate more. I've got a larger example that definitely fails in this way, but I obviously need to be a bit more careful isolating the circumstances in which it's happening. |
@heschik The test script now (hopefully!) demonstrates the issue correctly. |
Ah. Yes. That is unsurprising in retrospect. @ianthehat: Without looking I'd bet a small sum that it's because of this line in https://github.com/golang/tools/blob/cb89afadce946e09f295886d955e7135642e195c/imports/fix.go#L980 It should probably do the same thing as |
So I think https://go-review.googlesource.com/c/tools/+/160999 correctly tests the problem, now I just need to fix it... |
I guess the question is how fussy do we need to be about this. |
Hmm, I guess this is more complicated than I had initially given it credit for. Perhaps the best thing would be to directly special-case the package under test? Like, in fixImportsDefault, if the filename ends with _test, call loadExports on srcDir in a special mode and add that directly to the candidate list? |
Change https://golang.org/cl/213221 mentions this issue: |
What version of Go are you using (
go version
)?As of commit 0a99049, goimports does not seem to consider the local package as a candidate for an external test.
Here's a testscript example that demonstrates the issue:
I would expect running
goimports
on a.go to add an import ofexample.com/a
.The text was updated successfully, but these errors were encountered: