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: goimports still fails to distinguish package from global variable #23206
Comments
@wjessop Sorry for the basic question, but just to help with triage, are you sure you're running the latest version of goimports, but maybe more importantly, do you have a simple reproducer? If it's not easy to extract a simple standalone example that demonstrates this problem from your actual program, you could consider adapting one examples from the comments in #7463, or you could extract an example from one of the tests such as: |
Sure thing! I just ran To replicateCreate a dir:
Add main.go:
Add logger.go:
See the program runs:
Run goimports:
Re-run the program:
Inspect the new contents of main.go:
|
another example
|
The problem is the sibling code optimization which doesn't take much into account. There is already a separate issue on incorrect imports, this highlights the lack of Global tracking. I will take a crack at this with my existing PR on the import issue, #23001. |
Upon further evaluation, this is actually not an issue. -srcdir requires a value, preferably . or something valid. Once I do that, it executes properly. |
@wjessop I’m slightly curious how you first encountered this? For example, were you using goimports via your editor and saw something unexpected, and then you switched to the command line to troubleshoot, or _____? |
-srcdir defaults to the empty string. It seems -srcdir is (or at least was) related to the logic to detect globals within your package in a separate file (for example, from fatih/vim-go#956:
There’s also related discussion here: I’ll confess I do not 100% follow the exact interrelationship between the -srcdir option and the trailing All that said, given the use case for goimports is really tuned to being invoked by editors, it sounds like there might have been a conscious choice to do things this way based on other trade-offs or constraints (in other words, this might all be operating as currently designed). |
This is basically this issue. It looks like a fix was started, but wether it never got merged, or this is a regression I don't know, but It seems to have cropped up on a project I'm working on where it wasn't an issue before.
What version of Go are you using (
go version
)?go version go1.10beta1 darwin/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?The text was updated successfully, but these errors were encountered: