Skip to content

x/tools/cmd/goimports: moves comment to inappropriate line #23709

@dfawley

Description

@dfawley

Create a file with the following contents:

package main

import (
	"math" // fun
)

func main() {
	x := math.MaxInt64
	fmt.Println(strings.Join(",", []string{"hi"}), x)
}
$ goimports -d /tmp/a.go
diff -u /tmp/a.go.orig /tmp/a.go
--- /tmp/a.go.orig	2018-02-05 15:44:54.612402902 -0800
+++ /tmp/a.go	2018-02-05 15:44:54.612402902 -0800
@@ -1,7 +1,9 @@
 package main
 
 import (
-	"math" // fun
+	"fmt"
+	"math"
+	"strings" // fun
 )
 
 func main() {

Expected:

$ goimports -d /tmp/a.go
diff -u /tmp/a.go.orig /tmp/a.go
--- /tmp/a.go.orig	2018-02-05 15:44:54.612402902 -0800
+++ /tmp/a.go	2018-02-05 15:44:54.612402902 -0800
@@ -1,7 +1,9 @@
 package main
 
 import (
+	"fmt"
	"math" // fun
+	"strings"
 )
 
 func main() {

Versions tested:

go version go1.10rc1 linux/amd64
go version go1.9.3 linux/amd64

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions