Skip to content

Commit

Permalink
chore: add doc strings to methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kulti committed Dec 15, 2021
1 parent 95051f0 commit eaced58
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ func checkFunc(pass *analysis.Pass, reports *reports, funcDecl funcDecl, opts ch
}
}

// searchFuncParam search a function param with desired type.
// It returns the param field, its position, and true if something is found.
func searchFuncParam(pass *analysis.Pass, f funcDecl, p types.Type) (*ast.Field, int, bool) {
for i, f := range f.Type.Params.List {
if isExprHasType(pass, f.Type, p) {
Expand All @@ -342,6 +344,7 @@ func searchFuncParam(pass *analysis.Pass, f funcDecl, p types.Type) (*ast.Field,
return nil, 0, false
}

// isTHelperCall returns true if provided statement 's' is t.Helper() or b.Helper() call.
func isTHelperCall(pass *analysis.Pass, s ast.Stmt, tHelper types.Object) bool {
exprStmt, ok := s.(*ast.ExprStmt)
if !ok {
Expand All @@ -361,7 +364,8 @@ func isTHelperCall(pass *analysis.Pass, s ast.Stmt, tHelper types.Object) bool {
return isSelectorCall(pass, selExpr, tHelper)
}

func extractSubtestExp(pass *analysis.Pass, e *ast.CallExpr, tbRun types.Object) ast.Expr {
// extractSubtestExp analyzes that call expresion 'e' is t.Run or b.Run
// and returns subtest function.
selExpr, ok := e.Fun.(*ast.SelectorExpr)
if !ok {
return nil
Expand All @@ -378,6 +382,8 @@ func extractSubtestExp(pass *analysis.Pass, e *ast.CallExpr, tbRun types.Object)
return e.Args[1]
}

// funcDefPosition returns a function's position.
// It works with anonymous functions as well with function names.
func funcDefPosition(pass *analysis.Pass, e ast.Expr) token.Pos {
anonFunLit, ok := e.(*ast.FuncLit)
if ok {
Expand All @@ -401,6 +407,8 @@ func funcDefPosition(pass *analysis.Pass, e ast.Expr) token.Pos {
return funDef.Pos()
}

// isSelectorCall checks is selExpr is a call expresion on specific callObj.
// Useful to check Run() call for t.Run or b.Run.
func isSelectorCall(pass *analysis.Pass, selExpr *ast.SelectorExpr, callObj types.Object) bool {
sel, ok := pass.TypesInfo.Selections[selExpr]
if !ok {
Expand Down

0 comments on commit eaced58

Please sign in to comment.