nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: daixiang0/gci
Pull request #202 (2024-04-02 22:54:53)

fix: local module path matching
https://github.com/golangci/golangci-lint/issues/4608

The value `path` can't end with `/` because a module name can't end with `/`, so the append of `/` doesn't need to be checked.

This PR has no problem with modules without packages (`spec.Path == m.Path`).

Closes #203

daixiang0: @ldez thanks for your contribution!

Could you sign your commit then we can make it land?
ldez: the commits are already signed
daixiang0: Please sign commits refer to [this Github Doc](https://docs.github.com/articles/about-gpg/). After signed, we can see "verified" in the commits page.

Patch:
diff --git a/pkg/section/local_module.go b/pkg/section/local_module.go
index 5af74b3..50f41e5 100644
--- a/pkg/section/local_module.go
+++ b/pkg/section/local_module.go
@@ -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{}
 	}
 


Test patch:
diff --git a/pkg/section/local_module_test.go b/pkg/section/local_module_test.go
new file mode 100644
index 0000000..93702bf
--- /dev/null
+++ b/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)
+}