diff --git a/pkg/config/config.go b/pkg/config/config.go index 5b73a36de349..2d551e02f946 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -99,6 +99,12 @@ var DefaultExcludePatterns = []ExcludePattern{ Linter: "gosec", Why: "False positive is triggered by 'src, err := ioutil.ReadFile(filename)'", }, + { + ID: "EXC0011", + Pattern: "at least one file in a package should have a package comment", + Linter: "stylecheck", + Why: "Annoying issue about not having a package comment.", + }, } func GetDefaultExcludePatternsStrings() []string { @@ -121,6 +127,22 @@ func GetExcludePatternsStrings(include []string) []string { return ret } +func GetExcludePatterns(include []string) []ExcludePattern { + includeMap := make(map[string]bool, len(include)) + for _, inc := range include { + includeMap[inc] = true + } + + var ret []ExcludePattern + for _, p := range DefaultExcludePatterns { + if !includeMap[p.ID] { + ret = append(ret, p) + } + } + + return ret +} + type Run struct { IsVerbose bool `mapstructure:"verbose"` Silent bool diff --git a/pkg/golinters/goanalysis/runner.go b/pkg/golinters/goanalysis/runner.go index db193f37bb20..81225277eb77 100644 --- a/pkg/golinters/goanalysis/runner.go +++ b/pkg/golinters/goanalysis/runner.go @@ -3,7 +3,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// Package checker defines the implementation of the checker commands. +// Package goanalysis defines the implementation of the checker commands. // The same code drives the multi-analysis driver, the single-analysis // driver that is conventionally provided for convenience along with // each analysis package, and the test driver. diff --git a/pkg/golinters/gocognit.go b/pkg/golinters/gocognit.go index 78afff86c59b..d39f5234eaad 100644 --- a/pkg/golinters/gocognit.go +++ b/pkg/golinters/gocognit.go @@ -1,4 +1,4 @@ -// nolint:dupl +// nolint:dupl,stylecheck package golinters import ( diff --git a/pkg/golinters/gocyclo.go b/pkg/golinters/gocyclo.go index 55f13fcfed2f..0160512678b3 100644 --- a/pkg/golinters/gocyclo.go +++ b/pkg/golinters/gocyclo.go @@ -1,4 +1,4 @@ -// nolint:dupl +// nolint:dupl,stylecheck package golinters import ( diff --git a/pkg/lint/lintersdb/manager.go b/pkg/lint/lintersdb/manager.go index 52a230bd8053..ad197376b120 100644 --- a/pkg/lint/lintersdb/manager.go +++ b/pkg/lint/lintersdb/manager.go @@ -85,7 +85,7 @@ func enableLinterConfigs(lcs []*linter.Config, isEnabled func(lc *linter.Config) return ret } -//nolint:funlen +//nolint:funlen,stylecheck func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { var govetCfg *config.GovetSettings var testpackageCfg *config.TestpackageSettings diff --git a/pkg/lint/runner.go b/pkg/lint/runner.go index 084912226b63..5278f3ac2263 100644 --- a/pkg/lint/runner.go +++ b/pkg/lint/runner.go @@ -225,14 +225,10 @@ func (r *Runner) processIssues(issues []result.Issue, sw *timeutils.Stopwatch, s } func getExcludeProcessor(cfg *config.Issues) processors.Processor { - excludePatterns := cfg.ExcludePatterns - if cfg.UseDefaultExcludes { - excludePatterns = append(excludePatterns, config.GetExcludePatternsStrings(cfg.IncludeDefaultExcludes)...) - } - var excludeTotalPattern string - if len(excludePatterns) != 0 { - excludeTotalPattern = fmt.Sprintf("(%s)", strings.Join(excludePatterns, "|")) + excludeGlobalPatterns := cfg.ExcludePatterns + if len(excludeGlobalPatterns) != 0 { + excludeTotalPattern = fmt.Sprintf("(%s)", strings.Join(excludeGlobalPatterns, "|")) } var excludeProcessor processors.Processor @@ -258,6 +254,17 @@ func getExcludeRulesProcessor(cfg *config.Issues, log logutils.Log, lineCache *f }) } + if cfg.UseDefaultExcludes { + for _, r := range config.GetExcludePatterns(cfg.IncludeDefaultExcludes) { + excludeRules = append(excludeRules, processors.ExcludeRule{ + BaseRule: processors.BaseRule{ + Text: r.Pattern, + Linters: []string{r.Linter}, + }, + }) + } + } + var excludeRulesProcessor processors.Processor if cfg.ExcludeCaseSensitive { excludeRulesProcessor = processors.NewExcludeRulesCaseSensitive( diff --git a/pkg/packages/errors.go b/pkg/packages/errors.go index c620573b9380..92239b19991d 100644 --- a/pkg/packages/errors.go +++ b/pkg/packages/errors.go @@ -9,7 +9,7 @@ import ( "github.com/pkg/errors" ) -//nolint:gomnd +//nolint:gomnd,stylecheck func ParseErrorPosition(pos string) (*token.Position, error) { // file:line(:colon) parts := strings.Split(pos, ":") diff --git a/pkg/printers/github.go b/pkg/printers/github.go index b8d70140a80c..4ebc26685784 100644 --- a/pkg/printers/github.go +++ b/pkg/printers/github.go @@ -13,7 +13,7 @@ type github struct { const defaultGithubSeverity = "error" -// Github output format outputs issues according to Github actions format: +// NewGithub output format outputs issues according to Github actions format: // https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message func NewGithub() Printer { return &github{} diff --git a/pkg/result/processors/sort_results.go b/pkg/result/processors/sort_results.go index e726c3adfe05..cea3721c357e 100644 --- a/pkg/result/processors/sort_results.go +++ b/pkg/result/processors/sort_results.go @@ -91,10 +91,10 @@ var ( type ByName struct{ next comparator } -//nolint:golint +//nolint:golint,stylecheck func (cmp ByName) Next() comparator { return cmp.next } -//nolint:golint +//nolint:golint,stylecheck func (cmp ByName) Compare(a, b *result.Issue) compareResult { var res compareResult @@ -111,10 +111,10 @@ func (cmp ByName) Compare(a, b *result.Issue) compareResult { type ByLine struct{ next comparator } -//nolint:golint +//nolint:golint,stylecheck func (cmp ByLine) Next() comparator { return cmp.next } -//nolint:golint +//nolint:golint,stylecheck func (cmp ByLine) Compare(a, b *result.Issue) compareResult { var res compareResult @@ -131,10 +131,10 @@ func (cmp ByLine) Compare(a, b *result.Issue) compareResult { type ByColumn struct{ next comparator } -//nolint:golint +//nolint:golint,stylecheck func (cmp ByColumn) Next() comparator { return cmp.next } -//nolint:golint +//nolint:golint,stylecheck func (cmp ByColumn) Compare(a, b *result.Issue) compareResult { var res compareResult diff --git a/test/testdata/stylecheck.go b/test/testdata/stylecheck.go index a0d73053dfd9..43176747922c 100644 --- a/test/testdata/stylecheck.go +++ b/test/testdata/stylecheck.go @@ -1,4 +1,6 @@ //args: -Estylecheck + +/* Package testdata ... */ package testdata func Stylecheck(x int) {