-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.
Milestone
Description
I'm not sure if this is a bug or a feature request or known accepted behavior in goimports - I'll let @bradfitz decide, but consider the following unfinished Go program:
package main
import (
"fmt"
"image"
_ "image/png"
"os"
)
func main() {
var img image.Image // some image
err := png.Encode(os.Stdout, img)
fmt.Println(err)
}One would normally expect the png.Encode usage to cause goimports to add the image/png import.
However, it does nothing. It's because that package is already imported for side effects.
This was slightly unexpected. But I'm not sure what ideal behavior would be.
- Should it replace the underscore import with normal import? Probably not.
- Should it add a second entry for
image/png, keeping the underscore import alone? Maybe? - What about renamed packages, if there's a
pathpkg "path"import and someone writespath.Join, shouldgoimportsadd a second import forpathpackage? Or should underscore imports be treated differently than other renamed packages?
I'm only reporting this because I ran into it and it didn't seem to be reported already.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.