From c3f30136d7a945d4c740790f6cc7cb1d57f2fa31 Mon Sep 17 00:00:00 2001 From: Tom Arrell Date: Wed, 14 Oct 2026 15:42:25 +0200 Subject: [PATCH] fix: build against gobwas/glob v0 and v1 gobwas/glob v1.0.0 keeps the v0 module path but replaces the glob.Glob interface with *glob.Pattern. Any build that selects v1 fails to compile wrapcheck. A build selects v1 when another dependency requires it. Store compiled globs behind an unexported globMatcher interface, which both glob.Glob and *glob.Pattern satisfy. go.mod keeps requiring v0.2.3, so wrapcheck doesn't force consumers such as golangci-lint onto v1 before their other dependencies support it. Report the offending pattern in the glob compile error instead of the nil compiled value. Co-authored-by: David Symonds --- .github/workflows/test.yaml | 5 +++++ wrapcheck/wrapcheck.go | 25 ++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0d47bf4..0249a89 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -17,3 +17,8 @@ jobs: - name: Test run: go test ./... + + - name: Test with gobwas/glob v1 + run: | + go get github.com/gobwas/glob@v1.0.0 + go test ./... diff --git a/wrapcheck/wrapcheck.go b/wrapcheck/wrapcheck.go index 12cd156..a809a22 100644 --- a/wrapcheck/wrapcheck.go +++ b/wrapcheck/wrapcheck.go @@ -111,7 +111,7 @@ func run(cfg WrapcheckConfig) func(*analysis.Pass) (interface{}, error) { var ( ignoreSigRegexp []*regexp.Regexp ignoreInterfaceRegexps []*regexp.Regexp - ignorePackageGlobs []glob.Glob + ignorePackageGlobs []globMatcher err error ) @@ -274,7 +274,7 @@ func reportUnwrapped( cfg WrapcheckConfig, regexpsSig []*regexp.Regexp, regexpsInter []*regexp.Regexp, - pkgGlobs []glob.Glob, + pkgGlobs []globMatcher, ) { if cfg.ReportInternalErrors { @@ -347,7 +347,7 @@ func isInterface(pass *analysis.Pass, sel *ast.SelectorExpr) bool { // isFromotherPkg returns whether the function is defined in the package // currently under analysis or is considered external. It will ignore packages // defined in config.IgnorePackageGlobs. -func isFromOtherPkg(pass *analysis.Pass, sel *ast.SelectorExpr, pkgGlobs []glob.Glob) bool { +func isFromOtherPkg(pass *analysis.Pass, sel *ast.SelectorExpr, pkgGlobs []globMatcher) bool { // The package of the function that we are calling which returns the error fn := pass.TypesInfo.ObjectOf(sel.Sel) if containsMatchGlob(pkgGlobs, fn.Pkg().Path()) { @@ -436,7 +436,7 @@ func containsMatch(regexps []*regexp.Regexp, el string) bool { return false } -func containsMatchGlob(globs []glob.Glob, el string) bool { +func containsMatchGlob(globs []globMatcher, el string) bool { for _, g := range globs { if g.Match(el) { return true @@ -481,17 +481,24 @@ func compileRegexps(regexps []string) ([]*regexp.Regexp, error) { return compiledRegexps, nil } +// globMatcher is the subset of a compiled gobwas/glob pattern used by the +// analyzer. Both glob.Glob (v0) and *glob.Pattern (v1) satisfy it, so the +// analyzer builds against either version of the module. +type globMatcher interface { + Match(s string) bool +} + // compileGlobs compiles a set of globs, returning them for use, // or the first encountered error due to an invalid expression. -func compileGlobs(globs []string) ([]glob.Glob, error) { - compiledGlobs := make([]glob.Glob, len(globs)) +func compileGlobs(globs []string) ([]globMatcher, error) { + compiledGlobs := make([]globMatcher, len(globs)) for idx, globString := range globs { - glob, err := glob.Compile(globString) + g, err := glob.Compile(globString) if err != nil { - return nil, fmt.Errorf("unable to compile globs %s: %v\n", glob, err) + return nil, fmt.Errorf("unable to compile glob %q: %w", globString, err) } - compiledGlobs[idx] = glob + compiledGlobs[idx] = g } return compiledGlobs, nil }