Skip to content

Commit

Permalink
add new paralleltest linter (#1503)
Browse files Browse the repository at this point in the history
  • Loading branch information
kunwardeep committed Nov 22, 2020
1 parent c68692e commit b90551c
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -29,6 +29,7 @@ require (
github.com/jgautheron/goconst v0.0.0-20201117150253-ccae5bf973f3
github.com/jingyugao/rowserrcheck v0.0.0-20191204022205-72ab7603b68a
github.com/jirfag/go-printf-func-name v0.0.0-20191110105641-45db9963cdd3
github.com/kunwardeep/paralleltest v1.0.2
github.com/kyoh86/exportloopref v0.1.8
github.com/maratori/testpackage v1.0.1
github.com/matoous/godox v0.0.0-20190911065817-5d6d842e92eb // v1.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions pkg/golinters/paralleltest.go
@@ -0,0 +1,21 @@
package golinters

import (
"github.com/kunwardeep/paralleltest/pkg/paralleltest"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
)

func NewParallelTest() *goanalysis.Linter {
analyzers := []*analysis.Analyzer{
paralleltest.NewAnalyzer(),
}

return goanalysis.NewLinter(
"paralleltest",
"paralleltest detects missing usage of t.Parallel() method in your Go test",
analyzers,
nil,
).WithLoadMode(goanalysis.LoadModeTypesInfo)
}
4 changes: 4 additions & 0 deletions pkg/lint/lintersdb/manager.go
Expand Up @@ -324,6 +324,10 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
WithPresets(linter.PresetBugs).
WithLoadForGoAnalysis().
WithURL("https://github.com/polyfloyd/go-errorlint"),
linter.NewConfig(golinters.NewParallelTest()).
WithPresets(linter.PresetStyle).
WithLoadForGoAnalysis().
WithURL("https://github.com/kunwardeep/paralleltest"),

// nolintlint must be last because it looks at the results of all the previous linters for unused nolint directives
linter.NewConfig(golinters.NewNoLintLint()).
Expand Down
24 changes: 24 additions & 0 deletions test/testdata/paralleltest.go
@@ -0,0 +1,24 @@
//args: -Eparalleltest
package testdata

import (
"fmt"
"testing"
)

func TestFunctionSuccessfulRangeTest(t *testing.T) {
t.Parallel()

testCases := []struct {
name string
}{{name: "foo"}}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
fmt.Println(tc.name)
})
}
}

func TestFunctionMissingCallToParallel(t *testing.T) {} // ERROR "Function TestFunctionMissingCallToParallel missing the call to method parallel"

0 comments on commit b90551c

Please sign in to comment.