staticcheck: simplify CheckWaitgroupAdd
@@ -863,20 +863,8 @@ func CheckWaitgroupAdd(pass *analysis.Pass) (interface{}, error) {
if !ok {
return
}
- call, ok := stmt.X.(*ast.CallExpr)
- if !ok {
- return
- }
- sel, ok := call.Fun.(*ast.SelectorExpr)
- if !ok {
- return
- }
- fn, ok := pass.TypesInfo.ObjectOf(sel.Sel).(*types.Func)
- if !ok {
- return
- }
- if lint.FuncName(fn) == "(*sync.WaitGroup).Add" {
- pass.Reportf(sel.Pos(), "should call %s before starting the goroutine to avoid a race",
+ if IsCallToAST(pass, stmt.X, "(*sync.WaitGroup).Add") {
+ pass.Reportf(stmt.Pos(), "should call %s before starting the goroutine to avoid a race",
Render(pass, stmt))
}
}
