Skip to content

Commit

Permalink
Merge pull request #35 from ldez/fix/loopvar
Browse files Browse the repository at this point in the history
feat: add ignoreloopvar option
  • Loading branch information
kunwardeep authored Feb 15, 2024
2 parents 2ff338a + d304942 commit 2ac0c2f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ A few options can be activated by flag:

* `-i`: Ignore missing calls to `t.Parallel` and only report incorrect uses of it.
* `-ignoremissingsubtests`: Require that top-level tests specify `t.Parallel`, but don't require it in subtests (`t.Run(...)`).
* `-ignoreloopVar`: Ignore loop variable detection.

## Examples

Expand Down
4 changes: 3 additions & 1 deletion pkg/paralleltest/paralleltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type parallelAnalyzer struct {
analyzer *analysis.Analyzer
ignoreMissing bool
ignoreMissingSubtests bool
ignoreLoopVar bool
}

func newParallelAnalyzer() *parallelAnalyzer {
Expand All @@ -34,6 +35,7 @@ func newParallelAnalyzer() *parallelAnalyzer {
var flags flag.FlagSet
flags.BoolVar(&a.ignoreMissing, "i", false, "ignore missing calls to t.Parallel")
flags.BoolVar(&a.ignoreMissingSubtests, "ignoremissingsubtests", false, "ignore missing calls to t.Parallel in subtests")
flags.BoolVar(&a.ignoreLoopVar, "ignoreloopVar", false, "ignore loop variable detection")

a.analyzer = &analysis.Analyzer{
Name: "paralleltest",
Expand Down Expand Up @@ -137,7 +139,7 @@ func (a *parallelAnalyzer) run(pass *analysis.Pass) (interface{}, error) {
rangeStatementCantParallelMethod = methodSetenvIsCalledInMethodRun(r.X, innerTestVar)
}

if loopVariableUsedInRun == nil {
if !a.ignoreLoopVar && loopVariableUsedInRun == nil {
if run, ok := r.X.(*ast.CallExpr); ok {
loopVariableUsedInRun = loopVarReferencedInRun(run, loopVars, pass.TypesInfo)
}
Expand Down

0 comments on commit 2ac0c2f

Please sign in to comment.