@@ -234,15 +234,23 @@ func run(cfg WrapcheckConfig) func(*analysis.Pass) (interface{}, error) {
234
234
235
235
// Report unwrapped takes a call expression and an identifier and reports
236
236
// if the call is unwrapped.
237
- func reportUnwrapped (pass * analysis.Pass , call * ast.CallExpr , tokenPos token.Pos , cfg WrapcheckConfig , regexpsSig []* regexp.Regexp , regexpsInter []* regexp.Regexp , pkgGlobs []glob.Glob ) {
237
+ func reportUnwrapped (
238
+ pass * analysis.Pass ,
239
+ call * ast.CallExpr ,
240
+ tokenPos token.Pos ,
241
+ cfg WrapcheckConfig ,
242
+ regexpsSig []* regexp.Regexp ,
243
+ regexpsInter []* regexp.Regexp ,
244
+ pkgGlobs []glob.Glob ,
245
+ ) {
246
+
238
247
sel , ok := call .Fun .(* ast.SelectorExpr )
239
248
if ! ok {
240
249
return
241
250
}
242
251
243
252
// Check for ignored signatures
244
253
fnSig := pass .TypesInfo .ObjectOf (sel .Sel ).String ()
245
-
246
254
if contains (cfg .IgnoreSigs , fnSig ) {
247
255
return
248
256
} else if containsMatch (regexpsSig , fnSig ) {
@@ -253,9 +261,9 @@ func reportUnwrapped(pass *analysis.Pass, call *ast.CallExpr, tokenPos token.Pos
253
261
// errors returned from interface types should be wrapped, unless ignored
254
262
// as per `ignoreInterfaceRegexps`
255
263
if isInterface (pass , sel ) {
264
+ pkgPath := pass .TypesInfo .ObjectOf (sel .Sel ).Pkg ().Path ()
256
265
name := types .TypeString (pass .TypesInfo .TypeOf (sel .X ), func (p * types.Package ) string { return p .Name () })
257
- if containsMatch (regexpsInter , name ) {
258
- } else {
266
+ if ! containsMatch (regexpsInter , name ) && ! containsMatchGlob (pkgGlobs , pkgPath ) {
259
267
pass .Reportf (tokenPos , "error returned from interface method should be wrapped: sig: %s" , fnSig )
260
268
return
261
269
}
@@ -318,6 +326,7 @@ func prevErrAssign(pass *analysis.Pass, file *ast.File, returnIdent *ast.Ident)
318
326
if ! isError (pass .TypesInfo .TypeOf (expr )) {
319
327
continue
320
328
}
329
+
321
330
if assIdent , ok := expr .(* ast.Ident ); ok {
322
331
if assIdent .Obj == nil || returnIdent .Obj == nil {
323
332
// If we can't find the Obj for one of the identifiers, just skip
@@ -341,6 +350,7 @@ func prevErrAssign(pass *analysis.Pass, file *ast.File, returnIdent *ast.Ident)
341
350
if ass .Pos () > returnIdent .Pos () {
342
351
break
343
352
}
353
+
344
354
mostRecentAssign = ass
345
355
}
346
356
@@ -373,6 +383,7 @@ func containsMatchGlob(globs []glob.Glob, el string) bool {
373
383
return true
374
384
}
375
385
}
386
+
376
387
return false
377
388
}
378
389
0 commit comments