mirror of
https://github.com/golang/go
synced 2024-11-18 11:04:42 -07:00
internal/imports: only check first segment for .
An import path like "foo/bar.v1" is still a local path, not an external package, and should be grouped as such. Change-Id: I06be3c01076f616a3cdc8e23bc9c056643035ad1 Reviewed-on: https://go-review.googlesource.com/c/tools/+/234111 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
0aa9f2fd80
commit
444c5ef18e
@ -50,7 +50,8 @@ var importToGroup = []func(env *ProcessEnv, importPath string) (num int, ok bool
|
||||
return
|
||||
},
|
||||
func(_ *ProcessEnv, importPath string) (num int, ok bool) {
|
||||
if strings.Contains(importPath, ".") {
|
||||
firstComponent := strings.Split(importPath, "/")[0]
|
||||
if strings.Contains(firstComponent, ".") {
|
||||
return 1, true
|
||||
}
|
||||
return
|
||||
|
@ -846,7 +846,6 @@ import (
|
||||
var _ = fmt.Sprintf
|
||||
`,
|
||||
},
|
||||
|
||||
{
|
||||
name: "import_grouping_not_path_dependent_no_groups",
|
||||
in: `package main
|
||||
@ -2696,3 +2695,36 @@ func _() {
|
||||
wg.Wait()
|
||||
})
|
||||
}
|
||||
|
||||
func TestNonlocalDot(t *testing.T) {
|
||||
const input = `package main
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
var _, _ = fmt.Sprintf, dot.Dot
|
||||
`
|
||||
const want = `package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"noninternet/dot.v1/dot"
|
||||
)
|
||||
|
||||
var _, _ = fmt.Sprintf, dot.Dot
|
||||
`
|
||||
testConfig{
|
||||
modules: []packagestest.Module{
|
||||
{
|
||||
Name: "golang.org/fake",
|
||||
Files: fm{"x.go": input},
|
||||
},
|
||||
{
|
||||
Name: "noninternet/dot.v1",
|
||||
Files: fm{
|
||||
"dot/dot.go": "package dot\nfunc Dot(){}\n",
|
||||
},
|
||||
},
|
||||
},
|
||||
gopathOnly: true, // our modules testing setup doesn't allow modules without dots.
|
||||
}.processTest(t, "golang.org/fake", "x.go", nil, nil, want)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user