golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
121.01k stars 17.36k forks source link

x/tools/cmd/eg: clean imports after refactoring #21328

Open LOZORD opened 6 years ago

LOZORD commented 6 years ago

tl;dr: While new imports are correctly added by the refactoring, imports that are made obsolete still exist unnecessarily (and therefore break compilation). We need to run something like goimports after performing the eg transformation.

What version of Go are you using (go version)?

go version go1.8.1 darwin/amd64

What operating system and processor architecture are you using (go env)?

darwin/amd64

What did you do?

Leos-MBP:~ LeoRudberg$ go build golang.org/x/tools/cmd/eg
Leos-MBP:~ LeoRudberg$ go version
go version go1.8.1 darwin/amd64
Leos-MBP:~ LeoRudberg$ cat test-eg/template.go 
package template

import (
    "errors"
    "fmt"
)

func before(s string) error { return fmt.Errorf("%s", s) }
func after(s string) error  { return errors.New(s) }
Leos-MBP:~ LeoRudberg$ cat test-eg/example.go 
package example

import (
    "fmt"
)

func Whoops(s string) error {
    return fmt.Errorf("%s", "Whoops: "+s)
}
Leos-MBP:~ LeoRudberg$ eg -t test-eg/template.go test-eg/example.go 
=== test-eg/example.go (1 matches)
package example

import (
    "fmt"
    "errors"
)

func Whoops(s string) error {
    return errors.New("Whoops: " + s)
}

What did you expect to see?

The import section for the result should only contain errors.

What did you see instead?

The import section contained errors, but also fmt unnecessarily.

LOZORD commented 6 years ago

At Gophercon, @alaska started work on this I believe. @clairew also expressed interest in fixing this, too.

clairew commented 6 years ago

@LOZORD Thanks for issuing this - will take a look at what I can do!

gopherbot commented 6 years ago

Change https://golang.org/cl/77530 mentions this issue: refactor/eg: Fix all imports after modifying files.

gopherbot commented 6 years ago

Change https://golang.org/cl/116222 mentions this issue: refactor/eg: Fix all imports after modifying files.