Skip to content

Commit

Permalink
refactor: move building check options to separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
kulti committed Feb 21, 2021
1 parent a02a2da commit 8289e72
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions pkg/analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,7 @@ func NewAnalyzer() *analysis.Analyzer {
}

func (t thelper) run(pass *analysis.Pass) (interface{}, error) {
var ctxType types.Type
ctxObj := analysisutil.ObjectOf(pass, "context", "Context")
if ctxObj != nil {
ctxType = ctxObj.Type()
}

tCheckOpts, ok := t.buildTestCheckFuncOpts(pass, ctxType)
if !ok {
return nil, nil
}

bCheckOpts, ok := t.buildBenchmarkCheckFuncOpts(pass, ctxType)
if !ok {
return nil, nil
}

tbCheckOpts, ok := t.buildTBCheckFuncOpts(pass, ctxType)
tCheckOpts, bCheckOpts, tbCheckOpts, ok := t.buildCheckFuncOpts(pass)
if !ok {
return nil, nil
}
Expand Down Expand Up @@ -189,6 +173,31 @@ type checkFuncOpts struct {
checkName bool
}

func (t thelper) buildCheckFuncOpts(pass *analysis.Pass) (checkFuncOpts, checkFuncOpts, checkFuncOpts, bool) {
var ctxType types.Type
ctxObj := analysisutil.ObjectOf(pass, "context", "Context")
if ctxObj != nil {
ctxType = ctxObj.Type()
}

tCheckOpts, ok := t.buildTestCheckFuncOpts(pass, ctxType)
if !ok {
return checkFuncOpts{}, checkFuncOpts{}, checkFuncOpts{}, false
}

bCheckOpts, ok := t.buildBenchmarkCheckFuncOpts(pass, ctxType)
if !ok {
return checkFuncOpts{}, checkFuncOpts{}, checkFuncOpts{}, false
}

tbCheckOpts, ok := t.buildTBCheckFuncOpts(pass, ctxType)
if !ok {
return checkFuncOpts{}, checkFuncOpts{}, checkFuncOpts{}, false
}

return tCheckOpts, bCheckOpts, tbCheckOpts, true
}

func (t thelper) buildTestCheckFuncOpts(pass *analysis.Pass, ctxType types.Type) (checkFuncOpts, bool) {
tObj := analysisutil.ObjectOf(pass, "testing", "T")
if tObj == nil {
Expand Down

0 comments on commit 8289e72

Please sign in to comment.