Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: local module path matching #202

Merged
merged 1 commit into from Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/section/local_module.go
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
@@ -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)
}