Skip to content

Commit b90551c

Browse files
authored
add new paralleltest linter (#1503)
1 parent c68692e commit b90551c

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ require (
2929
github.com/jgautheron/goconst v0.0.0-20201117150253-ccae5bf973f3
3030
github.com/jingyugao/rowserrcheck v0.0.0-20191204022205-72ab7603b68a
3131
github.com/jirfag/go-printf-func-name v0.0.0-20191110105641-45db9963cdd3
32+
github.com/kunwardeep/paralleltest v1.0.2
3233
github.com/kyoh86/exportloopref v0.1.8
3334
github.com/maratori/testpackage v1.0.1
3435
github.com/matoous/godox v0.0.0-20190911065817-5d6d842e92eb // v1.0

go.sum

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/golinters/paralleltest.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package golinters
2+
3+
import (
4+
"github.com/kunwardeep/paralleltest/pkg/paralleltest"
5+
"golang.org/x/tools/go/analysis"
6+
7+
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
8+
)
9+
10+
func NewParallelTest() *goanalysis.Linter {
11+
analyzers := []*analysis.Analyzer{
12+
paralleltest.NewAnalyzer(),
13+
}
14+
15+
return goanalysis.NewLinter(
16+
"paralleltest",
17+
"paralleltest detects missing usage of t.Parallel() method in your Go test",
18+
analyzers,
19+
nil,
20+
).WithLoadMode(goanalysis.LoadModeTypesInfo)
21+
}

pkg/lint/lintersdb/manager.go

+4
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
324324
WithPresets(linter.PresetBugs).
325325
WithLoadForGoAnalysis().
326326
WithURL("https://github.com/polyfloyd/go-errorlint"),
327+
linter.NewConfig(golinters.NewParallelTest()).
328+
WithPresets(linter.PresetStyle).
329+
WithLoadForGoAnalysis().
330+
WithURL("https://github.com/kunwardeep/paralleltest"),
327331

328332
// nolintlint must be last because it looks at the results of all the previous linters for unused nolint directives
329333
linter.NewConfig(golinters.NewNoLintLint()).

test/testdata/paralleltest.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//args: -Eparalleltest
2+
package testdata
3+
4+
import (
5+
"fmt"
6+
"testing"
7+
)
8+
9+
func TestFunctionSuccessfulRangeTest(t *testing.T) {
10+
t.Parallel()
11+
12+
testCases := []struct {
13+
name string
14+
}{{name: "foo"}}
15+
for _, tc := range testCases {
16+
tc := tc
17+
t.Run(tc.name, func(t *testing.T) {
18+
t.Parallel()
19+
fmt.Println(tc.name)
20+
})
21+
}
22+
}
23+
24+
func TestFunctionMissingCallToParallel(t *testing.T) {} // ERROR "Function TestFunctionMissingCallToParallel missing the call to method parallel"

0 commit comments

Comments
 (0)