Open
Description
go version go1.8.3 darwin/amd64
Using goimports
as of golang/tools@84a35ef
The goimports
command handles import fixing and gofmt
code formatting. It does not, however, implement the code simplification option -s
.
This means that goimports
cannot be used as a drop-in replacement to save-hooks that use gofmt -s
(for example, when using -s
as the gofmt-args
value for the save-hook with go-mode.el
).
package main
import "fmt"
type Thing struct {
value int
}
func main() {
things := []Thing{
Thing{value: 42},
}
fmt.Printf("things: %+v\n", things)
}
There are no problems identified by goimports
:
$ goimports -d complex.go
With gofmt -s
, we get:
$ gofmt -s -d complex.go
diff complex.go gofmt/complex.go
--- /var/folders/ts/s940qvdj5vj1czr9qh07fvtw0000gn/T/gofmt822245016 2017-08-16 12:34:31.000000000 -0400
+++ /var/folders/ts/s940qvdj5vj1czr9qh07fvtw0000gn/T/gofmt235716375 2017-08-16 12:34:31.000000000 -0400
@@ -8,7 +8,7 @@
func main() {
things := []Thing{
- Thing{value: 42},
+ {value: 42},
}
fmt.Printf("things: %+v\n", things)
}