Skip to content

Commit

Permalink
fix: local module path matching (#202)
Browse files Browse the repository at this point in the history
Signed-off-by: Fernandez Ludovic <[email protected]>
  • Loading branch information
ldez authored Apr 3, 2024
1 parent 4f7ff3c commit 869c320
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/section/local_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type LocalModule struct {
}

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

Expand Down
18 changes: 18 additions & 0 deletions pkg/section/local_module_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package section

import (
"testing"

"github.com/daixiang0/gci/pkg/specificity"
)

func TestLocalModule_specificity(t *testing.T) {
testCases := []specificityTestData{
{"example.com/hello", &LocalModule{Path: "example.com/hello"}, specificity.LocalModule{}},
{"example.com/hello/world", &LocalModule{Path: "example.com/hello"}, specificity.LocalModule{}},
{"example.com/hello-world", &LocalModule{Path: "example.com/hello"}, specificity.MisMatch{}},
{"example.com/helloworld", &LocalModule{Path: "example.com/hello"}, specificity.MisMatch{}},
{"example.com", &LocalModule{Path: "example.com/hello"}, specificity.MisMatch{}},
}
testSpecificity(t, testCases)
}

0 comments on commit 869c320

Please sign in to comment.