mirror of
https://github.com/golang/go
synced 2024-11-18 12:14:42 -07:00
imports: support match without trailing slash for -local flag
Make it so that import prefixes specified using the -local flag are considered a match for an import path if the prefix ends with a '/' and the import path matches exactly the prefix without a slash. For example, specifying "golang.org/x/tools/" as a prefix would match the import for the package "golang.org/x/tools". Fixes golang/go#24368 Change-Id: I0302db72fda63ad24d7b964aa73f78aa0ebccb37 Reviewed-on: https://go-review.googlesource.com/100460 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
d853e8088c
commit
c41d143952
@ -49,7 +49,7 @@ func localPrefixes() []string {
|
||||
var importToGroup = []func(importPath string) (num int, ok bool){
|
||||
func(importPath string) (num int, ok bool) {
|
||||
for _, p := range localPrefixes() {
|
||||
if strings.HasPrefix(importPath, p) {
|
||||
if strings.HasPrefix(importPath, p) || strings.TrimSuffix(p, "/") == importPath {
|
||||
return 3, true
|
||||
}
|
||||
}
|
||||
|
@ -1444,6 +1444,29 @@ import (
|
||||
|
||||
const Y = bar.X
|
||||
const _ = runtime.GOOS
|
||||
`,
|
||||
},
|
||||
{
|
||||
config: testConfig{
|
||||
gopathFiles: map[string]string{
|
||||
"foo/foo.go": "package foo \n const X = 1",
|
||||
"foo/bar/bar.go": "package bar \n const X = 1",
|
||||
},
|
||||
},
|
||||
localPrefix: "foo/",
|
||||
src: "package main \n const Y = bar.X \n const Z = foo.X \n const _ = runtime.GOOS",
|
||||
want: `package main
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"foo"
|
||||
"foo/bar"
|
||||
)
|
||||
|
||||
const Y = bar.X
|
||||
const Z = foo.X
|
||||
const _ = runtime.GOOS
|
||||
`,
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user