wrapcheck
wrapcheck copied to clipboard
Embedded interfaces are hard to ignore
When an interface is embedded, the reported interface name isn't what you need to ignore. Concretely, extend wrapcheck/testdata/config_ignoreInterfaceRegexps/main.go
with the following, and run the test.
type embedder interface {
errorer
}
func embed(fn embedder) error {
var str string
return fn.Decode(&str) // errorer interface ignored as per `ignoreInterfaceRegexps`
}
Unexpectedly, you'll see the following:
--- FAIL: TestAnalyzer (5.40s) --- FAIL: TestAnalyzer/config_ignoreInterfaceRegexps (0.25s) analysistest.go:452: /home/murman/src/wrapcheck/wrapcheck/testdata/config_ignoreInterfaceRegexps/main.go:33:9: unexpected diagnostic: error returned from interface method should be wrapped: sig: func (_/home/murman/src/wrapcheck/wrapcheck/testdata/config_ignoreInterfaceRegexps.errorer).Decode(v interface{}) error
Note that the ignores include errorer
and the reported interface is config_ignoreInterfaceRegexps.errorer
. However to suppress this you actually need to suppress embedder
.
I believe this comes down to the difference between name and fnSig in reportUnwrapped, which come from sel.Sel and sel.X respectively, but the path forward is unclear to me. https://github.com/tomarrell/wrapcheck/blob/213318509af6a003be2be752da826d269149ba4d/wrapcheck/wrapcheck.go#L257-L260