Skip to content

x/tools/cmd/goimports:  #22045

@niko-fp

Description

@niko-fp

Please answer these questions before submitting your issue. Thanks!

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

go version go1.9 darwin/amd64

Does this issue reproduce with the latest release?

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

What did you do?

run goimports -d .

It seems to not work as expected when there is a line with a comment

What did you expect to see?

Having in test.go

package main

var (
	translationItemResponseChannel chan string
	version                        string
	environment                    string
	countryCode                    string
	// CacheControlMaxAge in minutes
	CacheControlMaxAge int
        anotherVarToFix string
)

goimports should fix it and align the types like this

$ goimports -d test.go
diff -u test.go.orig test.go
--- test.go.orig	2017-09-26 17:02:52.000000000 +0200
+++ test.go	2017-09-26 17:02:52.000000000 +0200
@@ -3,8 +3,8 @@
 var (
 	translationItemResponseChannel chan string
 	version                        string
-	environment         string
+	environment                    string
 	countryCode                    string
 	// CacheControlMaxAge in minutes
-	CacheControlMaxAge int
-	anotherVarToFix string
+	CacheControlMaxAge             int
+	anotherVarToFix                string
 )

What did you see instead?

But if there is a commented line in between, weird things happen

$ goimports -d test.go
diff -u test.go.orig test.go
--- test.go.orig	2017-09-26 17:00:40.000000000 +0200
+++ test.go	2017-09-26 17:00:40.000000000 +0200
@@ -3,9 +3,9 @@
 var (
 	translationItemResponseChannel chan string
 	version                        string
-	environment         string
+	environment                    string
 	countryCode                    string
 	// CacheControlMaxAge in minutes
 	CacheControlMaxAge int
-	anotherVarToFix string
+	anotherVarToFix    string
 )

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions