Skip to content

Commit

Permalink
patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyunhao116 committed Nov 6, 2020
1 parent 3fe444c commit 5b51dc8
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 19 deletions.
22 changes: 22 additions & 0 deletions pkg/config/config.go
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/goanalysis/runner.go
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/gocognit.go
@@ -1,4 +1,4 @@
// nolint:dupl
// nolint:dupl,stylecheck
package golinters

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/golinters/gocyclo.go
@@ -1,4 +1,4 @@
// nolint:dupl
// nolint:dupl,stylecheck
package golinters

import (
Expand Down
2 changes: 1 addition & 1 deletion pkg/lint/lintersdb/manager.go
Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions pkg/lint/runner.go
Expand Up @@ -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
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pkg/packages/errors.go
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/pkg/errors"
)

//nolint:gomnd
//nolint:gomnd,stylecheck
func ParseErrorPosition(pos string) (*token.Position, error) {
// file:line(<optional>:colon)
parts := strings.Split(pos, ":")
Expand Down
2 changes: 1 addition & 1 deletion pkg/printers/github.go
Expand Up @@ -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{}
Expand Down
12 changes: 6 additions & 6 deletions pkg/result/processors/sort_results.go
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions test/testdata/stylecheck.go
@@ -1,4 +1,6 @@
//args: -Estylecheck

/* Package testdata ... */
package testdata

func Stylecheck(x int) {
Expand Down

0 comments on commit 5b51dc8

Please sign in to comment.