diff --git a/go.mod b/go.mod index 22cc8ba..5a68df9 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23.0 toolchain go1.24.1 require ( - github.com/gobwas/glob v0.2.3 + github.com/gobwas/glob v1.0.0 golang.org/x/tools v0.31.0 ) diff --git a/go.sum b/go.sum index c297207..507a98c 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0= github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= -github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= -github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= +github.com/gobwas/glob v1.0.0 h1:p+FKbLEIsK1yZ39/OINwFvqNb5oyPY4H8xcy6uYu8dg= +github.com/gobwas/glob v1.0.0/go.mod h1:oWCdo522i2P1n/hMXGNWs7yoV4wy/ciZuUIbvKj5rkc= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU= diff --git a/settings.go b/settings.go index 5bc74f8..64b1c75 100644 --- a/settings.go +++ b/settings.go @@ -28,8 +28,8 @@ const ( type list struct { listMode listMode name string - files []glob.Glob - negFiles []glob.Glob + files []*glob.Pattern + negFiles []*glob.Pattern allow []string deny []string suggestions []string @@ -212,7 +212,7 @@ func (s linterSettings) whichLists(fileName string) []*list { return matches } -func strInGlobList(str string, globList []glob.Glob) bool { +func strInGlobList(str string, globList []*glob.Pattern) bool { for _, g := range globList { if g.Match(str) { return true diff --git a/settings_test.go b/settings_test.go index 4ce1af5..9f3497d 100644 --- a/settings_test.go +++ b/settings_test.go @@ -26,6 +26,10 @@ type settingsCompileScenario struct { expErr error } +func cmpGlobPattern(a, b *glob.Pattern) bool { + return a.String() == b.String() +} + var ( listCompileScenarios = []*listCompileScenario{ { @@ -56,7 +60,7 @@ var ( Allow: []string{"os"}, }, exp: &list{ - files: []glob.Glob{ + files: []*glob.Pattern{ glob.MustCompile("**/*.go", '/'), }, allow: []string{"os"}, @@ -69,7 +73,7 @@ var ( Allow: []string{"os"}, }, exp: &list{ - negFiles: []glob.Glob{ + negFiles: []*glob.Pattern{ glob.MustCompile("**/*_test.go", '/'), }, allow: []string{"os"}, @@ -82,10 +86,10 @@ var ( Allow: []string{"os"}, }, exp: &list{ - files: []glob.Glob{ + files: []*glob.Pattern{ glob.MustCompile("**/foo.go", '/'), }, - negFiles: []glob.Glob{ + negFiles: []*glob.Pattern{ glob.MustCompile("**/bar.go", '/'), }, allow: []string{"os"}, @@ -148,10 +152,10 @@ var ( }, }, exp: &list{ - files: []glob.Glob{ + files: []*glob.Pattern{ glob.MustCompile("**/*.go", '/'), }, - negFiles: []glob.Glob{ + negFiles: []*glob.Pattern{ glob.MustCompile("**/*_test.go", '/'), }, allow: []string{"os"}, @@ -240,7 +244,7 @@ var ( exp: []*list{ { name: "Main", - files: []glob.Glob{ + files: []*glob.Pattern{ glob.MustCompile("**/*.go", '/'), }, allow: []string{"FIND ME", "FIND ME TOO"}, @@ -262,14 +266,14 @@ var ( exp: []*list{ { name: "Main", - files: []glob.Glob{ + files: []*glob.Pattern{ glob.MustCompile("**/*.go", '/'), }, allow: []string{"os"}, }, { name: "Test", - files: []glob.Glob{ + files: []*glob.Pattern{ glob.MustCompile("**/*_test.go", '/'), }, allow: []string{"os"}, @@ -294,7 +298,7 @@ func testListCompile(s *listCompileScenario) func(*testing.T) { if err != nil { t.Fatal("not expecting an error") } - diff := cmp.Diff(s.exp, act, cmp.AllowUnexported(list{})) + diff := cmp.Diff(s.exp, act, cmp.AllowUnexported(list{}), cmp.Comparer(cmpGlobPattern)) if diff != "" { t.Errorf("compiled list is not what was expected\n%s", diff) } @@ -316,7 +320,7 @@ func testSettingsCompile(s *settingsCompileScenario) func(*testing.T) { if err != nil { t.Fatal("not expecting an error") } - diff := cmp.Diff(s.exp, act, cmp.AllowUnexported(list{})) + diff := cmp.Diff(s.exp, act, cmp.AllowUnexported(list{}), cmp.Comparer(cmpGlobPattern)) if diff != "" { t.Errorf("compiled settings is not what was expected\n%s", diff) } @@ -365,7 +369,7 @@ var ( "willd.io/normal/package", } - globList = []glob.Glob{ + globList = []*glob.Pattern{ glob.MustCompile("some/*/a", '/'), glob.MustCompile("some/**/a", '/'), } @@ -482,7 +486,7 @@ var listFileMatchScenarios = []*listFileMatchScenario{ { name: "Empty allow matches anything not in deny", setup: &list{ - negFiles: []glob.Glob{ + negFiles: []*glob.Pattern{ glob.MustCompile("**/*_test.go", '/'), }, }, @@ -507,7 +511,7 @@ var listFileMatchScenarios = []*listFileMatchScenario{ { name: "Empty deny only matches what is in allowed", setup: &list{ - files: []glob.Glob{ + files: []*glob.Pattern{ glob.MustCompile("**/*_test.go", '/'), }, }, @@ -532,10 +536,10 @@ var listFileMatchScenarios = []*listFileMatchScenario{ { name: "Both only allows what is in allow and not in deny", setup: &list{ - files: []glob.Glob{ + files: []*glob.Pattern{ glob.MustCompile("**/*.go", '/'), }, - negFiles: []glob.Glob{ + negFiles: []*glob.Pattern{ glob.MustCompile("**/*_test.go", '/'), }, }, @@ -931,13 +935,13 @@ type linterSettingsWhichListsScenario struct { var linterSettingsWhichListsSetup = linterSettings{ { name: "Main", - files: []glob.Glob{ + files: []*glob.Pattern{ glob.MustCompile("**/*.go", '/'), }, }, { name: "Test", - files: []glob.Glob{ + files: []*glob.Pattern{ glob.MustCompile("**/*_test.go", '/'), }, },