Skip to content

Commit 5b51dc8

Browse files
patch-1
1 parent 3fe444c commit 5b51dc8

File tree

10 files changed

+50
-19
lines changed

10 files changed

+50
-19
lines changed

pkg/config/config.go

+22
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ var DefaultExcludePatterns = []ExcludePattern{
9999
Linter: "gosec",
100100
Why: "False positive is triggered by 'src, err := ioutil.ReadFile(filename)'",
101101
},
102+
{
103+
ID: "EXC0011",
104+
Pattern: "at least one file in a package should have a package comment",
105+
Linter: "stylecheck",
106+
Why: "Annoying issue about not having a package comment.",
107+
},
102108
}
103109

104110
func GetDefaultExcludePatternsStrings() []string {
@@ -121,6 +127,22 @@ func GetExcludePatternsStrings(include []string) []string {
121127
return ret
122128
}
123129

130+
func GetExcludePatterns(include []string) []ExcludePattern {
131+
includeMap := make(map[string]bool, len(include))
132+
for _, inc := range include {
133+
includeMap[inc] = true
134+
}
135+
136+
var ret []ExcludePattern
137+
for _, p := range DefaultExcludePatterns {
138+
if !includeMap[p.ID] {
139+
ret = append(ret, p)
140+
}
141+
}
142+
143+
return ret
144+
}
145+
124146
type Run struct {
125147
IsVerbose bool `mapstructure:"verbose"`
126148
Silent bool

pkg/golinters/goanalysis/runner.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Use of this source code is governed by a BSD-style
44
// license that can be found in the LICENSE file.
55

6-
// Package checker defines the implementation of the checker commands.
6+
// Package goanalysis defines the implementation of the checker commands.
77
// The same code drives the multi-analysis driver, the single-analysis
88
// driver that is conventionally provided for convenience along with
99
// each analysis package, and the test driver.

pkg/golinters/gocognit.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// nolint:dupl
1+
// nolint:dupl,stylecheck
22
package golinters
33

44
import (

pkg/golinters/gocyclo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// nolint:dupl
1+
// nolint:dupl,stylecheck
22
package golinters
33

44
import (

pkg/lint/lintersdb/manager.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func enableLinterConfigs(lcs []*linter.Config, isEnabled func(lc *linter.Config)
8585
return ret
8686
}
8787

88-
//nolint:funlen
88+
//nolint:funlen,stylecheck
8989
func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
9090
var govetCfg *config.GovetSettings
9191
var testpackageCfg *config.TestpackageSettings

pkg/lint/runner.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,10 @@ func (r *Runner) processIssues(issues []result.Issue, sw *timeutils.Stopwatch, s
225225
}
226226

227227
func getExcludeProcessor(cfg *config.Issues) processors.Processor {
228-
excludePatterns := cfg.ExcludePatterns
229-
if cfg.UseDefaultExcludes {
230-
excludePatterns = append(excludePatterns, config.GetExcludePatternsStrings(cfg.IncludeDefaultExcludes)...)
231-
}
232-
233228
var excludeTotalPattern string
234-
if len(excludePatterns) != 0 {
235-
excludeTotalPattern = fmt.Sprintf("(%s)", strings.Join(excludePatterns, "|"))
229+
excludeGlobalPatterns := cfg.ExcludePatterns
230+
if len(excludeGlobalPatterns) != 0 {
231+
excludeTotalPattern = fmt.Sprintf("(%s)", strings.Join(excludeGlobalPatterns, "|"))
236232
}
237233

238234
var excludeProcessor processors.Processor
@@ -258,6 +254,17 @@ func getExcludeRulesProcessor(cfg *config.Issues, log logutils.Log, lineCache *f
258254
})
259255
}
260256

257+
if cfg.UseDefaultExcludes {
258+
for _, r := range config.GetExcludePatterns(cfg.IncludeDefaultExcludes) {
259+
excludeRules = append(excludeRules, processors.ExcludeRule{
260+
BaseRule: processors.BaseRule{
261+
Text: r.Pattern,
262+
Linters: []string{r.Linter},
263+
},
264+
})
265+
}
266+
}
267+
261268
var excludeRulesProcessor processors.Processor
262269
if cfg.ExcludeCaseSensitive {
263270
excludeRulesProcessor = processors.NewExcludeRulesCaseSensitive(

pkg/packages/errors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/pkg/errors"
1010
)
1111

12-
//nolint:gomnd
12+
//nolint:gomnd,stylecheck
1313
func ParseErrorPosition(pos string) (*token.Position, error) {
1414
// file:line(<optional>:colon)
1515
parts := strings.Split(pos, ":")

pkg/printers/github.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type github struct {
1313

1414
const defaultGithubSeverity = "error"
1515

16-
// Github output format outputs issues according to Github actions format:
16+
// NewGithub output format outputs issues according to Github actions format:
1717
// https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message
1818
func NewGithub() Printer {
1919
return &github{}

pkg/result/processors/sort_results.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ var (
9191

9292
type ByName struct{ next comparator }
9393

94-
//nolint:golint
94+
//nolint:golint,stylecheck
9595
func (cmp ByName) Next() comparator { return cmp.next }
9696

97-
//nolint:golint
97+
//nolint:golint,stylecheck
9898
func (cmp ByName) Compare(a, b *result.Issue) compareResult {
9999
var res compareResult
100100

@@ -111,10 +111,10 @@ func (cmp ByName) Compare(a, b *result.Issue) compareResult {
111111

112112
type ByLine struct{ next comparator }
113113

114-
//nolint:golint
114+
//nolint:golint,stylecheck
115115
func (cmp ByLine) Next() comparator { return cmp.next }
116116

117-
//nolint:golint
117+
//nolint:golint,stylecheck
118118
func (cmp ByLine) Compare(a, b *result.Issue) compareResult {
119119
var res compareResult
120120

@@ -131,10 +131,10 @@ func (cmp ByLine) Compare(a, b *result.Issue) compareResult {
131131

132132
type ByColumn struct{ next comparator }
133133

134-
//nolint:golint
134+
//nolint:golint,stylecheck
135135
func (cmp ByColumn) Next() comparator { return cmp.next }
136136

137-
//nolint:golint
137+
//nolint:golint,stylecheck
138138
func (cmp ByColumn) Compare(a, b *result.Issue) compareResult {
139139
var res compareResult
140140

test/testdata/stylecheck.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//args: -Estylecheck
2+
3+
/* Package testdata ... */
24
package testdata
35

46
func Stylecheck(x int) {

0 commit comments

Comments
 (0)