diff --git a/.golangci.reference.yml b/.golangci.reference.yml index 64c980c5f233..58859d8a60f1 100644 --- a/.golangci.reference.yml +++ b/.golangci.reference.yml @@ -1632,6 +1632,11 @@ linters-settings: # Regexp pattern to skip files. # Default: "(export|internal)_test\\.go" skip-regexp: (export|internal)_test\.go + # List of packages that don't end with _test that tests are allowed to be in. + # Default: "main" + allow-packages: + - example + - main thelper: test: diff --git a/go.mod b/go.mod index 8ed0c150c392..6b3c1997a06e 100644 --- a/go.mod +++ b/go.mod @@ -55,7 +55,7 @@ require ( github.com/ldez/tagliatelle v0.3.1 github.com/leonklingele/grouper v1.1.0 github.com/lufeee/execinquery v1.2.1 - github.com/maratori/testpackage v1.0.1 + github.com/maratori/testpackage v1.1.0 github.com/matoous/godox v0.0.0-20210227103229-6504466cf951 // v1.0 github.com/mattn/go-colorable v0.1.12 github.com/mbilski/exhaustivestruct v1.2.0 diff --git a/go.sum b/go.sum index 2dee0de2f096..5fcbca7e5bb1 100644 --- a/go.sum +++ b/go.sum @@ -428,8 +428,8 @@ github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2 github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= -github.com/maratori/testpackage v1.0.1 h1:QtJ5ZjqapShm0w5DosRjg0PRlSdAdlx+W6cCKoALdbQ= -github.com/maratori/testpackage v1.0.1/go.mod h1:ddKdw+XG0Phzhx8BFDTKgpWP4i7MpApTE5fXSKAqwDU= +github.com/maratori/testpackage v1.1.0 h1:GJY4wlzQhuBusMF1oahQCBtUV/AQ/k69IZ68vxaac2Q= +github.com/maratori/testpackage v1.1.0/go.mod h1:PeAhzU8qkCwdGEMTEupsHJNlQu2gZopMC6RjbhmHeDc= github.com/matoous/godox v0.0.0-20210227103229-6504466cf951 h1:pWxk9e//NbPwfxat7RXkts09K+dEBJWakUWwICVqYbA= github.com/matoous/godox v0.0.0-20210227103229-6504466cf951/go.mod h1:1BELzlh859Sh1c6+90blK8lbYy0kwQf1bYlBhBysy1s= github.com/matryer/is v1.4.0 h1:sosSmIWwkYITGrxZ25ULNDeKiMNzFSr4V/eqBQP0PeE= @@ -1028,7 +1028,6 @@ golang.org/x/tools v0.0.0-20200324003944-a576cf524670/go.mod h1:Sl4aGygMT6LrqrWc golang.org/x/tools v0.0.0-20200329025819-fd4102a86c65/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= golang.org/x/tools v0.0.0-20200414032229-332987a829c3/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200422022333-3d57cf2e726e/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200426102838-f3a5411a4c3b/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index c91f4f057e7d..3609958c69b8 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -88,7 +88,8 @@ var defaultLintersSettings = LintersSettings{ Qualified: false, }, Testpackage: TestpackageSettings{ - SkipRegexp: `(export|internal)_test\.go`, + SkipRegexp: `(export|internal)_test\.go`, + AllowPackages: []string{"main"}, }, Unparam: UnparamSettings{ Algo: "cha", @@ -558,7 +559,8 @@ type TagliatelleSettings struct { } type TestpackageSettings struct { - SkipRegexp string `mapstructure:"skip-regexp"` + SkipRegexp string `mapstructure:"skip-regexp"` + AllowPackages []string `mapstructure:"allow-packages"` } type ThelperSettings struct { diff --git a/pkg/golinters/testpackage.go b/pkg/golinters/testpackage.go index 836403826c14..2cc627595ff1 100644 --- a/pkg/golinters/testpackage.go +++ b/pkg/golinters/testpackage.go @@ -1,6 +1,8 @@ package golinters import ( + "strings" + "github.com/maratori/testpackage/pkg/testpackage" "golang.org/x/tools/go/analysis" @@ -15,7 +17,8 @@ func NewTestpackage(cfg *config.TestpackageSettings) *goanalysis.Linter { if cfg != nil { settings = map[string]map[string]interface{}{ a.Name: { - testpackage.SkipRegexpFlagName: cfg.SkipRegexp, + testpackage.SkipRegexpFlagName: cfg.SkipRegexp, + testpackage.AllowPackagesFlagName: strings.Join(cfg.AllowPackages, ","), }, } }