Skip to content

Commit 869c320

Browse files
authored
fix: local module path matching (#202)
Signed-off-by: Fernandez Ludovic <[email protected]>
1 parent 4f7ff3c commit 869c320

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

pkg/section/local_module.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type LocalModule struct {
1818
}
1919

2020
func (m *LocalModule) MatchSpecificity(spec *parse.GciImports) specificity.MatchSpecificity {
21-
if strings.HasPrefix(spec.Path, m.Path) {
21+
if spec.Path == m.Path || strings.HasPrefix(spec.Path, m.Path+"/") {
2222
return specificity.LocalModule{}
2323
}
2424

pkg/section/local_module_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package section
2+
3+
import (
4+
"testing"
5+
6+
"github.com/daixiang0/gci/pkg/specificity"
7+
)
8+
9+
func TestLocalModule_specificity(t *testing.T) {
10+
testCases := []specificityTestData{
11+
{"example.com/hello", &LocalModule{Path: "example.com/hello"}, specificity.LocalModule{}},
12+
{"example.com/hello/world", &LocalModule{Path: "example.com/hello"}, specificity.LocalModule{}},
13+
{"example.com/hello-world", &LocalModule{Path: "example.com/hello"}, specificity.MisMatch{}},
14+
{"example.com/helloworld", &LocalModule{Path: "example.com/hello"}, specificity.MisMatch{}},
15+
{"example.com", &LocalModule{Path: "example.com/hello"}, specificity.MisMatch{}},
16+
}
17+
testSpecificity(t, testCases)
18+
}

0 commit comments

Comments
 (0)