Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ignoreloopvar option #35

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading