-
Notifications
You must be signed in to change notification settings - Fork 646
goimports fails to consider global variables in package #630
Comments
The reason why I changed from passing the filename to passing the filecontents via stdin was that previously formatting an unsaved file, forcefully saved the file. #613 is an issue that I put a fix in where I pass the I'll see if that fixes your case. If not will look into your suggestions. Regardless, I'll push an update on Monday that will contain a fix to your issue |
I have reverted the said change in the latest update (0.6.50). |
@briantkennedy I am working on bringing back the "pass file contents via stdin to formatter" feature. But Did you have any plans to add the same option to |
Hi Ramya, thanks for reaching out, but I presently don't have any plans to add it to goreturns. It looks like sqs has plans to implement the feature request, so things should get resolved sooner or later. |
Thanks @briantkennedy! |
I just updated to 0.6.49 and format on save is now broken for goimports. After looking at recent changes, I believe that b143a0d triggered the breakage.
The difference is that the text for the file is passed via stdin instead of providing the on-disk filename. The consequence of passing from stdin is that the goimports process is not able to determine what global variables exist within the package. For example, if the global variable "log" is declared foo.go, while saving bar.go which calls "log.Info" or some other function which the "log" package declares, the command will operate on local data and assume you want to import the "log" package rather than using the package global variable which results in the tool incorrectly adding the "log" import.
The fix for this is to do one of the following:
Unfortunately, there doesn't appear to be a way to configure the current filename as a parameter in "go.FormatFlags" otherwise that would be an easy workaround.
The text was updated successfully, but these errors were encountered: