-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.This label describes issues relating to any tools in the x/tools repository.
Milestone
Description
What version of Go are you using (go version)?
$ go version go1.13.4
Does this issue reproduce with the latest release?
yes
What did you do?
I have some code with wrong import group,
this is the demo code:
package main
import (
"fmt"
"golang.org/x/tools/go/ast/astutil"
"abc.com/a/d/dao"
"abc.com/a/d/model"
"golang.org/x/tools/go/ast/inspector"
"strings"
)
type aliasA = astutil.ApplyFunc
var aliasB = dao.Table
var aliasC = model.Redis
var aliasD = inspector.AST
func main(){
fmt.Println("hello")
fmt.Println(strings.Join([]string{"hello","golang"}," "))
}
What did you expect to see?
$ goimports -local abc.com/a/d demo.go
package main
import (
"fmt"
"strings"
"golang.org/x/tools/go/ast/astutil"
"golang.org/x/tools/go/ast/inspector"
"abc.com/a/d/dao"
"abc.com/a/d/model"
)
type aliasA = astutil.ApplyFunc
var aliasB = dao.Table
var aliasC = model.Redis
var aliasD = inspector.AST
func main() {
fmt.Println("hello")
fmt.Println(strings.Join([]string{"hello", "golang"}, " "))
}
What did you see instead?
the strings and golang.org/x/tools/go/ast/inspector are at the wrong group:
package main
import (
"fmt"
"golang.org/x/tools/go/ast/astutil"
"strings"
"golang.org/x/tools/go/ast/inspector"
"abc.com/a/d/dao"
"abc.com/a/d/model"
)
type aliasA = astutil.ApplyFunc
var aliasB = dao.Table
var aliasC = model.Redis
var aliasD = inspector.AST
func main() {
fmt.Println("hello")
fmt.Println(strings.Join([]string{"hello", "golang"}, " "))
}
if the raw file's import section is like this, goimports can got the right code:
import (
"fmt"
"golang.org/x/tools/go/ast/astutil"
"abc.com/a/d/dao"
"abc.com/a/d/model"
"golang.org/x/tools/go/ast/inspector"
"strings"
)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.This label describes issues relating to any tools in the x/tools repository.