dev: removes BaseRule, ExcludeRule, SeverityRule duplications (#4676)
This commit is contained in:
parent
b2df2f4877
commit
55b2f5ddeb
@ -80,8 +80,8 @@ func NewRunner(log logutils.Log, cfg *config.Config, args []string, goenv *gouti
|
||||
// Must be before exclude because users see already marked output and configure excluding by it.
|
||||
processors.NewIdentifierMarker(),
|
||||
|
||||
getExcludeProcessor(&cfg.Issues),
|
||||
getExcludeRulesProcessor(&cfg.Issues, log, files),
|
||||
processors.NewExclude(&cfg.Issues),
|
||||
processors.NewExcludeRules(log.Child(logutils.DebugKeyExcludeRules), files, &cfg.Issues),
|
||||
processors.NewNolint(log.Child(logutils.DebugKeyNolint), dbManager, enabledLinters),
|
||||
|
||||
processors.NewUniqByLine(cfg),
|
||||
@ -91,7 +91,7 @@ func NewRunner(log logutils.Log, cfg *config.Config, args []string, goenv *gouti
|
||||
processors.NewMaxFromLinter(cfg.Issues.MaxIssuesPerLinter, log.Child(logutils.DebugKeyMaxFromLinter), cfg),
|
||||
processors.NewSourceCode(lineCache, log.Child(logutils.DebugKeySourceCode)),
|
||||
processors.NewPathShortener(),
|
||||
getSeverityRulesProcessor(&cfg.Severity, log, files),
|
||||
processors.NewSeverity(log.Child(logutils.DebugKeySeverityRules), files, &cfg.Severity),
|
||||
|
||||
// The fixer still needs to see paths for the issues that are relative to the current directory.
|
||||
processors.NewFixer(cfg, log, fileCache),
|
||||
@ -242,72 +242,3 @@ func (r *Runner) processIssues(issues []result.Issue, sw *timeutils.Stopwatch, s
|
||||
|
||||
return issues
|
||||
}
|
||||
|
||||
func getExcludeProcessor(cfg *config.Issues) processors.Processor {
|
||||
opts := processors.ExcludeOptions{
|
||||
CaseSensitive: cfg.ExcludeCaseSensitive,
|
||||
}
|
||||
|
||||
if len(cfg.ExcludePatterns) != 0 {
|
||||
opts.Pattern = fmt.Sprintf("(%s)", strings.Join(cfg.ExcludePatterns, "|"))
|
||||
}
|
||||
|
||||
return processors.NewExclude(opts)
|
||||
}
|
||||
|
||||
func getExcludeRulesProcessor(cfg *config.Issues, log logutils.Log, files *fsutils.Files) processors.Processor {
|
||||
var excludeRules []processors.ExcludeRule
|
||||
for _, r := range cfg.ExcludeRules {
|
||||
excludeRules = append(excludeRules, processors.ExcludeRule{
|
||||
BaseRule: processors.BaseRule{
|
||||
Text: r.Text,
|
||||
Source: r.Source,
|
||||
Path: r.Path,
|
||||
PathExcept: r.PathExcept,
|
||||
Linters: r.Linters,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
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},
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
opts := processors.ExcludeRulesOptions{
|
||||
Rules: excludeRules,
|
||||
CaseSensitive: cfg.ExcludeCaseSensitive,
|
||||
}
|
||||
|
||||
return processors.NewExcludeRules(log.Child(logutils.DebugKeyExcludeRules), files, opts)
|
||||
}
|
||||
|
||||
func getSeverityRulesProcessor(cfg *config.Severity, log logutils.Log, files *fsutils.Files) processors.Processor {
|
||||
var severityRules []processors.SeverityRule
|
||||
for _, r := range cfg.Rules {
|
||||
severityRules = append(severityRules, processors.SeverityRule{
|
||||
Severity: r.Severity,
|
||||
BaseRule: processors.BaseRule{
|
||||
Text: r.Text,
|
||||
Source: r.Source,
|
||||
Path: r.Path,
|
||||
PathExcept: r.PathExcept,
|
||||
Linters: r.Linters,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
severityOpts := processors.SeverityOptions{
|
||||
Default: cfg.Default,
|
||||
Rules: severityRules,
|
||||
CaseSensitive: cfg.CaseSensitive,
|
||||
}
|
||||
|
||||
return processors.NewSeverity(log.Child(logutils.DebugKeySeverityRules), files, severityOpts)
|
||||
}
|
||||
|
@ -10,14 +10,6 @@ import (
|
||||
|
||||
const caseInsensitivePrefix = "(?i)"
|
||||
|
||||
type BaseRule struct {
|
||||
Text string
|
||||
Source string
|
||||
Path string
|
||||
PathExcept string
|
||||
Linters []string
|
||||
}
|
||||
|
||||
type baseRule struct {
|
||||
text *regexp.Regexp
|
||||
source *regexp.Regexp
|
||||
|
@ -1,8 +1,11 @@
|
||||
package processors
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/config"
|
||||
"github.com/golangci/golangci-lint/pkg/result"
|
||||
)
|
||||
|
||||
@ -14,22 +17,22 @@ type Exclude struct {
|
||||
pattern *regexp.Regexp
|
||||
}
|
||||
|
||||
type ExcludeOptions struct {
|
||||
Pattern string
|
||||
CaseSensitive bool
|
||||
}
|
||||
|
||||
func NewExclude(opts ExcludeOptions) *Exclude {
|
||||
func NewExclude(cfg *config.Issues) *Exclude {
|
||||
p := &Exclude{name: "exclude"}
|
||||
|
||||
var pattern string
|
||||
if len(cfg.ExcludePatterns) != 0 {
|
||||
pattern = fmt.Sprintf("(%s)", strings.Join(cfg.ExcludePatterns, "|"))
|
||||
}
|
||||
|
||||
prefix := caseInsensitivePrefix
|
||||
if opts.CaseSensitive {
|
||||
if cfg.ExcludeCaseSensitive {
|
||||
p.name = "exclude-case-sensitive"
|
||||
prefix = ""
|
||||
}
|
||||
|
||||
if opts.Pattern != "" {
|
||||
p.pattern = regexp.MustCompile(prefix + opts.Pattern)
|
||||
if pattern != "" {
|
||||
p.pattern = regexp.MustCompile(prefix + pattern)
|
||||
}
|
||||
|
||||
return p
|
||||
|
@ -3,6 +3,7 @@ package processors
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/config"
|
||||
"github.com/golangci/golangci-lint/pkg/fsutils"
|
||||
"github.com/golangci/golangci-lint/pkg/logutils"
|
||||
"github.com/golangci/golangci-lint/pkg/result"
|
||||
@ -14,10 +15,6 @@ type excludeRule struct {
|
||||
baseRule
|
||||
}
|
||||
|
||||
type ExcludeRule struct {
|
||||
BaseRule
|
||||
}
|
||||
|
||||
type ExcludeRules struct {
|
||||
name string
|
||||
|
||||
@ -27,12 +24,7 @@ type ExcludeRules struct {
|
||||
rules []excludeRule
|
||||
}
|
||||
|
||||
type ExcludeRulesOptions struct {
|
||||
Rules []ExcludeRule
|
||||
CaseSensitive bool
|
||||
}
|
||||
|
||||
func NewExcludeRules(log logutils.Log, files *fsutils.Files, opts ExcludeRulesOptions) *ExcludeRules {
|
||||
func NewExcludeRules(log logutils.Log, files *fsutils.Files, cfg *config.Issues) *ExcludeRules {
|
||||
p := &ExcludeRules{
|
||||
name: "exclude-rules",
|
||||
files: files,
|
||||
@ -40,12 +32,25 @@ func NewExcludeRules(log logutils.Log, files *fsutils.Files, opts ExcludeRulesOp
|
||||
}
|
||||
|
||||
prefix := caseInsensitivePrefix
|
||||
if opts.CaseSensitive {
|
||||
if cfg.ExcludeCaseSensitive {
|
||||
prefix = ""
|
||||
p.name = "exclude-rules-case-sensitive"
|
||||
}
|
||||
|
||||
p.rules = createRules(opts.Rules, prefix)
|
||||
excludeRules := cfg.ExcludeRules
|
||||
|
||||
if cfg.UseDefaultExcludes {
|
||||
for _, r := range config.GetExcludePatterns(cfg.IncludeDefaultExcludes) {
|
||||
excludeRules = append(excludeRules, config.ExcludeRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Text: r.Pattern,
|
||||
Linters: []string{r.Linter},
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
p.rules = createRules(excludeRules, prefix)
|
||||
|
||||
return p
|
||||
}
|
||||
@ -71,7 +76,7 @@ func (p ExcludeRules) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||
|
||||
func (ExcludeRules) Finish() {}
|
||||
|
||||
func createRules(rules []ExcludeRule, prefix string) []excludeRule {
|
||||
func createRules(rules []config.ExcludeRule, prefix string) []excludeRule {
|
||||
parsedRules := make([]excludeRule, 0, len(rules))
|
||||
|
||||
for _, rule := range rules {
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/config"
|
||||
"github.com/golangci/golangci-lint/pkg/fsutils"
|
||||
"github.com/golangci/golangci-lint/pkg/result"
|
||||
)
|
||||
@ -15,33 +16,33 @@ func TestExcludeRules_multiple(t *testing.T) {
|
||||
lineCache := fsutils.NewLineCache(fsutils.NewFileCache())
|
||||
files := fsutils.NewFiles(lineCache, "")
|
||||
|
||||
opts := ExcludeRulesOptions{Rules: []ExcludeRule{
|
||||
opts := &config.Issues{ExcludeRules: []config.ExcludeRule{
|
||||
{
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Text: "^exclude$",
|
||||
Linters: []string{"linter"},
|
||||
},
|
||||
},
|
||||
{
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Linters: []string{"testlinter"},
|
||||
Path: `_test\.go`,
|
||||
},
|
||||
},
|
||||
{
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Text: "^testonly$",
|
||||
Path: `_test\.go`,
|
||||
},
|
||||
},
|
||||
{
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Text: "^nontestonly$",
|
||||
PathExcept: `_test\.go`,
|
||||
},
|
||||
},
|
||||
{
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Source: "^//go:generate ",
|
||||
Linters: []string{"lll"},
|
||||
},
|
||||
@ -94,10 +95,10 @@ func TestExcludeRules_pathPrefix(t *testing.T) {
|
||||
pathPrefix := path.Join("some", "dir")
|
||||
files := fsutils.NewFiles(lineCache, pathPrefix)
|
||||
|
||||
opts := ExcludeRulesOptions{
|
||||
Rules: []ExcludeRule{
|
||||
opts := &config.Issues{
|
||||
ExcludeRules: []config.ExcludeRule{
|
||||
{
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Path: `some/dir/e\.go`,
|
||||
},
|
||||
},
|
||||
@ -136,10 +137,10 @@ func TestExcludeRules_pathPrefix(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExcludeRules_text(t *testing.T) {
|
||||
opts := ExcludeRulesOptions{
|
||||
Rules: []ExcludeRule{
|
||||
opts := &config.Issues{
|
||||
ExcludeRules: []config.ExcludeRule{
|
||||
{
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Text: "^exclude$",
|
||||
Linters: []string{"linter"},
|
||||
},
|
||||
@ -170,36 +171,36 @@ func TestExcludeRules_text(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExcludeRules_empty(t *testing.T) {
|
||||
processAssertSame(t, NewExcludeRules(nil, nil, ExcludeRulesOptions{}), newIssueFromTextTestCase("test"))
|
||||
processAssertSame(t, NewExcludeRules(nil, nil, &config.Issues{}), newIssueFromTextTestCase("test"))
|
||||
}
|
||||
|
||||
func TestExcludeRules_caseSensitive_multiple(t *testing.T) {
|
||||
lineCache := fsutils.NewLineCache(fsutils.NewFileCache())
|
||||
files := fsutils.NewFiles(lineCache, "")
|
||||
|
||||
opts := ExcludeRulesOptions{
|
||||
CaseSensitive: true,
|
||||
Rules: []ExcludeRule{
|
||||
opts := &config.Issues{
|
||||
ExcludeCaseSensitive: true,
|
||||
ExcludeRules: []config.ExcludeRule{
|
||||
{
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Text: "^exclude$",
|
||||
Linters: []string{"linter"},
|
||||
},
|
||||
},
|
||||
{
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Linters: []string{"testlinter"},
|
||||
Path: `_test\.go`,
|
||||
},
|
||||
},
|
||||
{
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Text: "^testonly$",
|
||||
Path: `_test\.go`,
|
||||
},
|
||||
},
|
||||
{
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Source: "^//go:generate ",
|
||||
Linters: []string{"lll"},
|
||||
},
|
||||
@ -251,11 +252,11 @@ func TestExcludeRules_caseSensitive_multiple(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExcludeRules_caseSensitive_text(t *testing.T) {
|
||||
opts := ExcludeRulesOptions{
|
||||
CaseSensitive: true,
|
||||
Rules: []ExcludeRule{
|
||||
opts := &config.Issues{
|
||||
ExcludeCaseSensitive: true,
|
||||
ExcludeRules: []config.ExcludeRule{
|
||||
{
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Text: "^exclude$",
|
||||
Linters: []string{"linter"},
|
||||
},
|
||||
@ -287,5 +288,5 @@ func TestExcludeRules_caseSensitive_text(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExcludeRules_caseSensitive_empty(t *testing.T) {
|
||||
processAssertSame(t, NewExcludeRules(nil, nil, ExcludeRulesOptions{CaseSensitive: true}), newIssueFromTextTestCase("test"))
|
||||
processAssertSame(t, NewExcludeRules(nil, nil, &config.Issues{ExcludeCaseSensitive: true}), newIssueFromTextTestCase("test"))
|
||||
}
|
||||
|
@ -5,11 +5,12 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/config"
|
||||
"github.com/golangci/golangci-lint/pkg/result"
|
||||
)
|
||||
|
||||
func TestExclude(t *testing.T) {
|
||||
p := NewExclude(ExcludeOptions{Pattern: "^exclude$"})
|
||||
p := NewExclude(&config.Issues{ExcludePatterns: []string{"^exclude$"}})
|
||||
|
||||
texts := []string{"excLude", "1", "", "exclud", "notexclude"}
|
||||
|
||||
@ -30,11 +31,11 @@ func TestExclude(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestExclude_empty(t *testing.T) {
|
||||
processAssertSame(t, NewExclude(ExcludeOptions{}), newIssueFromTextTestCase("test"))
|
||||
processAssertSame(t, NewExclude(&config.Issues{}), newIssueFromTextTestCase("test"))
|
||||
}
|
||||
|
||||
func TestExclude_caseSensitive(t *testing.T) {
|
||||
p := NewExclude(ExcludeOptions{Pattern: "^exclude$", CaseSensitive: true})
|
||||
p := NewExclude(&config.Issues{ExcludePatterns: []string{"^exclude$"}, ExcludeCaseSensitive: true})
|
||||
|
||||
texts := []string{"excLude", "1", "", "exclud", "exclude"}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package processors
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/config"
|
||||
"github.com/golangci/golangci-lint/pkg/fsutils"
|
||||
"github.com/golangci/golangci-lint/pkg/logutils"
|
||||
"github.com/golangci/golangci-lint/pkg/result"
|
||||
@ -17,17 +18,6 @@ type severityRule struct {
|
||||
severity string
|
||||
}
|
||||
|
||||
type SeverityRule struct {
|
||||
BaseRule
|
||||
Severity string
|
||||
}
|
||||
|
||||
type SeverityOptions struct {
|
||||
Default string
|
||||
Rules []SeverityRule
|
||||
CaseSensitive bool
|
||||
}
|
||||
|
||||
type Severity struct {
|
||||
name string
|
||||
|
||||
@ -39,21 +29,21 @@ type Severity struct {
|
||||
rules []severityRule
|
||||
}
|
||||
|
||||
func NewSeverity(log logutils.Log, files *fsutils.Files, opts SeverityOptions) *Severity {
|
||||
func NewSeverity(log logutils.Log, files *fsutils.Files, cfg *config.Severity) *Severity {
|
||||
p := &Severity{
|
||||
name: "severity-rules",
|
||||
files: files,
|
||||
log: log,
|
||||
defaultSeverity: opts.Default,
|
||||
defaultSeverity: cfg.Default,
|
||||
}
|
||||
|
||||
prefix := caseInsensitivePrefix
|
||||
if opts.CaseSensitive {
|
||||
if cfg.CaseSensitive {
|
||||
prefix = ""
|
||||
p.name = "severity-rules-case-sensitive"
|
||||
}
|
||||
|
||||
p.rules = createSeverityRules(opts.Rules, prefix)
|
||||
p.rules = createSeverityRules(cfg.Rules, prefix)
|
||||
|
||||
return p
|
||||
}
|
||||
@ -93,7 +83,7 @@ func (p *Severity) transform(issue *result.Issue) *result.Issue {
|
||||
return issue
|
||||
}
|
||||
|
||||
func createSeverityRules(rules []SeverityRule, prefix string) []severityRule {
|
||||
func createSeverityRules(rules []config.SeverityRule, prefix string) []severityRule {
|
||||
parsedRules := make([]severityRule, 0, len(rules))
|
||||
|
||||
for _, rule := range rules {
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/golangci/golangci-lint/pkg/config"
|
||||
"github.com/golangci/golangci-lint/pkg/fsutils"
|
||||
"github.com/golangci/golangci-lint/pkg/logutils"
|
||||
"github.com/golangci/golangci-lint/pkg/result"
|
||||
@ -17,58 +18,58 @@ func TestSeverity_multiple(t *testing.T) {
|
||||
files := fsutils.NewFiles(lineCache, "")
|
||||
log := logutils.NewStderrLog(logutils.DebugKeyEmpty)
|
||||
|
||||
opts := SeverityOptions{
|
||||
opts := &config.Severity{
|
||||
Default: "error",
|
||||
Rules: []SeverityRule{
|
||||
Rules: []config.SeverityRule{
|
||||
{
|
||||
Severity: "info",
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Text: "^ssl$",
|
||||
Linters: []string{"gosec"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Severity: "info",
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Linters: []string{"linter"},
|
||||
Path: "e.go",
|
||||
},
|
||||
},
|
||||
{
|
||||
Severity: "info",
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Text: "^testonly$",
|
||||
Path: `_test\.go`,
|
||||
},
|
||||
},
|
||||
{
|
||||
Severity: "info",
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Text: "^nontestonly$",
|
||||
PathExcept: `_test\.go`,
|
||||
},
|
||||
},
|
||||
{
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Source: "^//go:generate ",
|
||||
Linters: []string{"lll"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Severity: "info",
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Source: "^//go:dosomething",
|
||||
},
|
||||
},
|
||||
{
|
||||
Severity: "info",
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Linters: []string{"someotherlinter"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Severity: "info",
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Linters: []string{"somelinter"},
|
||||
},
|
||||
},
|
||||
@ -133,12 +134,12 @@ func TestSeverity_pathPrefix(t *testing.T) {
|
||||
files := fsutils.NewFiles(lineCache, pathPrefix)
|
||||
log := logutils.NewStderrLog(logutils.DebugKeyEmpty)
|
||||
|
||||
opts := SeverityOptions{
|
||||
opts := &config.Severity{
|
||||
Default: "error",
|
||||
Rules: []SeverityRule{
|
||||
Rules: []config.SeverityRule{
|
||||
{
|
||||
Severity: "info",
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Text: "some",
|
||||
Path: `some/dir/e\.go`,
|
||||
},
|
||||
@ -180,10 +181,10 @@ func TestSeverity_pathPrefix(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSeverity_text(t *testing.T) {
|
||||
opts := SeverityOptions{
|
||||
Rules: []SeverityRule{
|
||||
opts := &config.Severity{
|
||||
Rules: []config.SeverityRule{
|
||||
{
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Text: "^severity$",
|
||||
Linters: []string{"linter"},
|
||||
},
|
||||
@ -218,12 +219,12 @@ func TestSeverity_onlyDefault(t *testing.T) {
|
||||
files := fsutils.NewFiles(lineCache, "")
|
||||
log := logutils.NewStderrLog(logutils.DebugKeyEmpty)
|
||||
|
||||
opts := SeverityOptions{
|
||||
opts := config.Severity{
|
||||
Default: "info",
|
||||
Rules: []SeverityRule{},
|
||||
Rules: []config.SeverityRule{},
|
||||
}
|
||||
|
||||
p := NewSeverity(log, files, opts)
|
||||
p := NewSeverity(log, files, &opts)
|
||||
|
||||
cases := []issueTestCase{
|
||||
{Path: "ssl.go", Text: "ssl", Linter: "gosec"},
|
||||
@ -257,7 +258,7 @@ func TestSeverity_onlyDefault(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSeverity_empty(t *testing.T) {
|
||||
p := NewSeverity(nil, nil, SeverityOptions{})
|
||||
p := NewSeverity(nil, nil, &config.Severity{})
|
||||
|
||||
processAssertSame(t, p, newIssueFromTextTestCase("test"))
|
||||
}
|
||||
@ -266,12 +267,12 @@ func TestSeverity_caseSensitive(t *testing.T) {
|
||||
lineCache := fsutils.NewLineCache(fsutils.NewFileCache())
|
||||
files := fsutils.NewFiles(lineCache, "")
|
||||
|
||||
opts := SeverityOptions{
|
||||
opts := &config.Severity{
|
||||
Default: "error",
|
||||
Rules: []SeverityRule{
|
||||
Rules: []config.SeverityRule{
|
||||
{
|
||||
Severity: "info",
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Text: "^ssl$",
|
||||
Linters: []string{"gosec", "someotherlinter"},
|
||||
},
|
||||
@ -317,18 +318,18 @@ func TestSeverity_transform(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
desc string
|
||||
opts SeverityOptions
|
||||
opts *config.Severity
|
||||
issue *result.Issue
|
||||
expected *result.Issue
|
||||
}{
|
||||
{
|
||||
desc: "apply severity from rule",
|
||||
opts: SeverityOptions{
|
||||
opts: &config.Severity{
|
||||
Default: "error",
|
||||
Rules: []SeverityRule{
|
||||
Rules: []config.SeverityRule{
|
||||
{
|
||||
Severity: "info",
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Linters: []string{"linter1"},
|
||||
},
|
||||
},
|
||||
@ -346,12 +347,12 @@ func TestSeverity_transform(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "apply severity from default",
|
||||
opts: SeverityOptions{
|
||||
opts: &config.Severity{
|
||||
Default: "error",
|
||||
Rules: []SeverityRule{
|
||||
Rules: []config.SeverityRule{
|
||||
{
|
||||
Severity: "info",
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Linters: []string{"linter1"},
|
||||
},
|
||||
},
|
||||
@ -369,12 +370,12 @@ func TestSeverity_transform(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "severity from rule override severity from linter",
|
||||
opts: SeverityOptions{
|
||||
opts: &config.Severity{
|
||||
Default: "error",
|
||||
Rules: []SeverityRule{
|
||||
Rules: []config.SeverityRule{
|
||||
{
|
||||
Severity: "info",
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Linters: []string{"linter1"},
|
||||
},
|
||||
},
|
||||
@ -393,12 +394,12 @@ func TestSeverity_transform(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "severity from default override severity from linter",
|
||||
opts: SeverityOptions{
|
||||
opts: &config.Severity{
|
||||
Default: "error",
|
||||
Rules: []SeverityRule{
|
||||
Rules: []config.SeverityRule{
|
||||
{
|
||||
Severity: "info",
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Linters: []string{"linter1"},
|
||||
},
|
||||
},
|
||||
@ -417,12 +418,12 @@ func TestSeverity_transform(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "keep severity from linter as rule",
|
||||
opts: SeverityOptions{
|
||||
opts: &config.Severity{
|
||||
Default: "error",
|
||||
Rules: []SeverityRule{
|
||||
Rules: []config.SeverityRule{
|
||||
{
|
||||
Severity: severityFromLinter,
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Linters: []string{"linter1"},
|
||||
},
|
||||
},
|
||||
@ -441,12 +442,12 @@ func TestSeverity_transform(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "keep severity from linter as default",
|
||||
opts: SeverityOptions{
|
||||
opts: &config.Severity{
|
||||
Default: severityFromLinter,
|
||||
Rules: []SeverityRule{
|
||||
Rules: []config.SeverityRule{
|
||||
{
|
||||
Severity: "info",
|
||||
BaseRule: BaseRule{
|
||||
BaseRule: config.BaseRule{
|
||||
Linters: []string{"linter1"},
|
||||
},
|
||||
},
|
||||
@ -465,7 +466,7 @@ func TestSeverity_transform(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "keep severity from linter as default (without rule)",
|
||||
opts: SeverityOptions{
|
||||
opts: &config.Severity{
|
||||
Default: severityFromLinter,
|
||||
},
|
||||
issue: &result.Issue{
|
||||
|
Loading…
x
Reference in New Issue
Block a user