diff --git a/.golangci.reference.yml b/.golangci.reference.yml index 5b1a77ecef94..b19e682ebd02 100644 --- a/.golangci.reference.yml +++ b/.golangci.reference.yml @@ -1607,6 +1607,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/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, ","), }, } }