Issue 8729 in go: goimports: inserted import mixed with preexisting comment

12 views
Skip to first unread message

g...@googlecode.com

unread,
Sep 14, 2014, 11:46:09 PM9/14/14
to golan...@googlegroups.com
Status: Accepted
Owner: brad...@golang.org
Labels: Release-None Repo-Tools

New issue 8729 by r...@golang.org: goimports: inserted import mixed with
preexisting comment
https://code.google.com/p/go/issues/detail?id=8729

g% cat exports.go
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package cgotest

import "C"

//export ReturnIntLong
func ReturnIntLong() (int, C.long) {
return 1, 2
}

//export gc
func gc() {
runtime.GC()
}
g%

g% goimports exports.go
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package cgotest

import "C"
import

//export ReturnIntLong
"runtime"

func ReturnIntLong() (int, C.long) {
return 1, 2
}

//export gc
func gc() {
runtime.GC()
}
g%

Look at how import and "runtime" are separated by the //export comment.


--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

g...@googlecode.com

unread,
Sep 15, 2014, 6:46:24 AM9/15/14
to golan...@googlegroups.com
Updates:
Owner: g...@golang.org

Comment #1 on issue 8729 by brad...@golang.org: goimports: inserted import
Reassigning to gri@. This feels like one of those scary AST token position
battles.

g...@googlecode.com

unread,
Sep 27, 2014, 7:36:02 PM9/27/14
to golan...@googlegroups.com

Comment #2 on issue 8729 by shurc...@gmail.com: goimports: inserted import
Here's another reproduce case for this, without import "C" (but with 3rd
party imports; I couldn't reproduce it with standard library imports only).

package u9

import (
)

// AddTabSupport is a helper that modifies a <textarea>, so that pressing
tab key will insert tabs.
func AddTabSupport(textArea *dom.HTMLTextAreaElement) {
var ke *dom.KeyboardEvent
inputEvent := js.Global.Get("CustomEvent").New("input")
}

Actual output after running goimports:

package u9

import (
"github.com/gopherjs/gopherjs/js"

// AddTabSupport is a helper that modifies a <textarea>, so that pressing
tab key will insert tabs.
"honnef.co/go/js/dom"
)

func AddTabSupport(textArea *dom.HTMLTextAreaElement) {
var ke *dom.KeyboardEvent
_ = js.Global
}

Note that the "// AddTabSupport ..." comment moved.

Expected output:

package u9

import (
"github.com/gopherjs/gopherjs/js"
"honnef.co/go/js/dom"
)

// AddTabSupport is a helper that modifies a <textarea>, so that pressing
tab key will insert tabs.
func AddTabSupport(textArea *dom.HTMLTextAreaElement) {
var ke *dom.KeyboardEvent
_ = js.Global
}

(It requires having those 2 packages in GOPATH.)

g...@googlecode.com

unread,
Sep 27, 2014, 7:37:02 PM9/27/14
to golan...@googlegroups.com

Comment #3 on issue 8729 by shurc...@gmail.com: goimports: inserted import
mixed with preexisting comment
https://code.google.com/p/go/issues/detail?id=8729

Here's another reproduce case for this, without import "C" (but with 3rd
party imports; I couldn't reproduce it with standard library imports only).

package u9

import (
)

// AddTabSupport is a helper that modifies a <textarea>, so that pressing
tab key will insert tabs.
func AddTabSupport(textArea *dom.HTMLTextAreaElement) {
var ke *dom.KeyboardEvent
_ = js.Global
}

Actual output after running goimports:

package u9

import (
"github.com/gopherjs/gopherjs/js"

// AddTabSupport is a helper that modifies a <textarea>, so that pressing
tab key will insert tabs.
"honnef.co/go/js/dom"
)

func AddTabSupport(textArea *dom.HTMLTextAreaElement) {
var ke *dom.KeyboardEvent
_ = js.Global
}

Note that the "// AddTabSupport ..." comment moved.

g...@googlecode.com

unread,
Dec 5, 2014, 8:25:35 PM12/5/14
to golan...@googlegroups.com

Comment #4 on issue 8729 by joshar...@gmail.com: goimports: inserted import
Started: CL 186870043. Will mail after the Great GitHub Migration of 2014.

Brad, do you know of a large body of goimports-formatted code? I'd like to
run this new version over it and make sure nothing changes.
Reply all
Reply to author
Forward
0 new messages