1
0
mirror of https://github.com/golang/go synced 2024-11-05 11:46:12 -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:
Heschi Kreinick 2020-05-15 13:30:44 -04:00
parent 0aa9f2fd80
commit 444c5ef18e
2 changed files with 35 additions and 2 deletions

View File

@ -50,7 +50,8 @@ var importToGroup = []func(env *ProcessEnv, importPath string) (num int, ok bool
return return
}, },
func(_ *ProcessEnv, importPath string) (num int, ok bool) { 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 1, true
} }
return return

View File

@ -846,7 +846,6 @@ import (
var _ = fmt.Sprintf var _ = fmt.Sprintf
`, `,
}, },
{ {
name: "import_grouping_not_path_dependent_no_groups", name: "import_grouping_not_path_dependent_no_groups",
in: `package main in: `package main
@ -2696,3 +2695,36 @@ func _() {
wg.Wait() 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)
}