mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-08-28 22:28:43 -04:00
add ability to set issue severity (#1155)
* add ability to set issue severity for out formats that support it based on severity rules * fix lint issues * change log child name * code climate omit severity if empty * add tests for severity rules, add support for case sensitive rules, fix lint issues, better doc comments, share processor test * deduplicated rule logic into a base rule that can be used by multiple rule types, moved severity config to it's own parent key named severity, reduced size of NewRunner function to make it easier to read * put validate function under base rule struct * better validation error wording * add Fingerprint and Description methods to Issue struct, made codeclimate reporter easier to read, checkstyle output is now pretty printed
This commit is contained in:
parent
dc260be693
commit
fa7adcbda9
18 changed files with 691 additions and 225 deletions
|
@ -1,7 +1,6 @@
|
|||
package processors
|
||||
|
||||
import (
|
||||
"go/token"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
|
@ -15,24 +14,32 @@ func TestExcludeRulesMultiple(t *testing.T) {
|
|||
lineCache := fsutils.NewLineCache(fsutils.NewFileCache())
|
||||
p := NewExcludeRules([]ExcludeRule{
|
||||
{
|
||||
Text: "^exclude$",
|
||||
Linters: []string{"linter"},
|
||||
BaseRule: BaseRule{
|
||||
Text: "^exclude$",
|
||||
Linters: []string{"linter"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Linters: []string{"testlinter"},
|
||||
Path: `_test\.go`,
|
||||
BaseRule: BaseRule{
|
||||
Linters: []string{"testlinter"},
|
||||
Path: `_test\.go`,
|
||||
},
|
||||
},
|
||||
{
|
||||
Text: "^testonly$",
|
||||
Path: `_test\.go`,
|
||||
BaseRule: BaseRule{
|
||||
Text: "^testonly$",
|
||||
Path: `_test\.go`,
|
||||
},
|
||||
},
|
||||
{
|
||||
Source: "^//go:generate ",
|
||||
Linters: []string{"lll"},
|
||||
BaseRule: BaseRule{
|
||||
Source: "^//go:generate ",
|
||||
Linters: []string{"lll"},
|
||||
},
|
||||
},
|
||||
}, lineCache, nil)
|
||||
|
||||
cases := []issueCase{
|
||||
cases := []issueTestCase{
|
||||
{Path: "e.go", Text: "exclude", Linter: "linter"},
|
||||
{Path: "e.go", Text: "some", Linter: "linter"},
|
||||
{Path: "e_test.go", Text: "normal", Linter: "testlinter"},
|
||||
|
@ -43,19 +50,19 @@ func TestExcludeRulesMultiple(t *testing.T) {
|
|||
}
|
||||
var issues []result.Issue
|
||||
for _, c := range cases {
|
||||
issues = append(issues, newIssueCase(c))
|
||||
issues = append(issues, newIssueFromIssueTestCase(c))
|
||||
}
|
||||
processedIssues := process(t, p, issues...)
|
||||
var resultingCases []issueCase
|
||||
var resultingCases []issueTestCase
|
||||
for _, i := range processedIssues {
|
||||
resultingCases = append(resultingCases, issueCase{
|
||||
resultingCases = append(resultingCases, issueTestCase{
|
||||
Path: i.FilePath(),
|
||||
Linter: i.FromLinter,
|
||||
Text: i.Text,
|
||||
Line: i.Line(),
|
||||
})
|
||||
}
|
||||
expectedCases := []issueCase{
|
||||
expectedCases := []issueTestCase{
|
||||
{Path: "e.go", Text: "some", Linter: "linter"},
|
||||
{Path: "e_Test.go", Text: "normal", Linter: "testlinter"},
|
||||
{Path: "e_test.go", Text: "another", Linter: "linter"},
|
||||
|
@ -63,30 +70,12 @@ func TestExcludeRulesMultiple(t *testing.T) {
|
|||
assert.Equal(t, expectedCases, resultingCases)
|
||||
}
|
||||
|
||||
type issueCase struct {
|
||||
Path string
|
||||
Line int
|
||||
Text string
|
||||
Linter string
|
||||
}
|
||||
|
||||
func newIssueCase(c issueCase) result.Issue {
|
||||
return result.Issue{
|
||||
Text: c.Text,
|
||||
FromLinter: c.Linter,
|
||||
Pos: token.Position{
|
||||
Filename: c.Path,
|
||||
Line: c.Line,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func TestExcludeRulesText(t *testing.T) {
|
||||
p := NewExcludeRules([]ExcludeRule{
|
||||
{
|
||||
Text: "^exclude$",
|
||||
Linters: []string{
|
||||
"linter",
|
||||
BaseRule: BaseRule{
|
||||
Text: "^exclude$",
|
||||
Linters: []string{"linter"},
|
||||
},
|
||||
},
|
||||
}, nil, nil)
|
||||
|
@ -110,31 +99,39 @@ func TestExcludeRulesText(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestExcludeRulesEmpty(t *testing.T) {
|
||||
processAssertSame(t, NewExcludeRules(nil, nil, nil), newTextIssue("test"))
|
||||
processAssertSame(t, NewExcludeRules(nil, nil, nil), newIssueFromTextTestCase("test"))
|
||||
}
|
||||
|
||||
func TestExcludeRulesCaseSensitiveMultiple(t *testing.T) {
|
||||
lineCache := fsutils.NewLineCache(fsutils.NewFileCache())
|
||||
p := NewExcludeRulesCaseSensitive([]ExcludeRule{
|
||||
{
|
||||
Text: "^exclude$",
|
||||
Linters: []string{"linter"},
|
||||
BaseRule: BaseRule{
|
||||
Text: "^exclude$",
|
||||
Linters: []string{"linter"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Linters: []string{"testlinter"},
|
||||
Path: `_test\.go`,
|
||||
BaseRule: BaseRule{
|
||||
Linters: []string{"testlinter"},
|
||||
Path: `_test\.go`,
|
||||
},
|
||||
},
|
||||
{
|
||||
Text: "^testonly$",
|
||||
Path: `_test\.go`,
|
||||
BaseRule: BaseRule{
|
||||
Text: "^testonly$",
|
||||
Path: `_test\.go`,
|
||||
},
|
||||
},
|
||||
{
|
||||
Source: "^//go:generate ",
|
||||
Linters: []string{"lll"},
|
||||
BaseRule: BaseRule{
|
||||
Source: "^//go:generate ",
|
||||
Linters: []string{"lll"},
|
||||
},
|
||||
},
|
||||
}, lineCache, nil)
|
||||
|
||||
cases := []issueCase{
|
||||
cases := []issueTestCase{
|
||||
{Path: "e.go", Text: "exclude", Linter: "linter"},
|
||||
{Path: "e.go", Text: "excLude", Linter: "linter"},
|
||||
{Path: "e.go", Text: "some", Linter: "linter"},
|
||||
|
@ -147,19 +144,19 @@ func TestExcludeRulesCaseSensitiveMultiple(t *testing.T) {
|
|||
}
|
||||
var issues []result.Issue
|
||||
for _, c := range cases {
|
||||
issues = append(issues, newIssueCase(c))
|
||||
issues = append(issues, newIssueFromIssueTestCase(c))
|
||||
}
|
||||
processedIssues := process(t, p, issues...)
|
||||
var resultingCases []issueCase
|
||||
var resultingCases []issueTestCase
|
||||
for _, i := range processedIssues {
|
||||
resultingCases = append(resultingCases, issueCase{
|
||||
resultingCases = append(resultingCases, issueTestCase{
|
||||
Path: i.FilePath(),
|
||||
Linter: i.FromLinter,
|
||||
Text: i.Text,
|
||||
Line: i.Line(),
|
||||
})
|
||||
}
|
||||
expectedCases := []issueCase{
|
||||
expectedCases := []issueTestCase{
|
||||
{Path: "e.go", Text: "excLude", Linter: "linter"},
|
||||
{Path: "e.go", Text: "some", Linter: "linter"},
|
||||
{Path: "e_Test.go", Text: "normal", Linter: "testlinter"},
|
||||
|
@ -173,9 +170,9 @@ func TestExcludeRulesCaseSensitiveMultiple(t *testing.T) {
|
|||
func TestExcludeRulesCaseSensitiveText(t *testing.T) {
|
||||
p := NewExcludeRulesCaseSensitive([]ExcludeRule{
|
||||
{
|
||||
Text: "^exclude$",
|
||||
Linters: []string{
|
||||
"linter",
|
||||
BaseRule: BaseRule{
|
||||
Text: "^exclude$",
|
||||
Linters: []string{"linter"},
|
||||
},
|
||||
},
|
||||
}, nil, nil)
|
||||
|
@ -199,5 +196,5 @@ func TestExcludeRulesCaseSensitiveText(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestExcludeRulesCaseSensitiveEmpty(t *testing.T) {
|
||||
processAssertSame(t, NewExcludeRulesCaseSensitive(nil, nil, nil), newTextIssue("test"))
|
||||
processAssertSame(t, NewExcludeRulesCaseSensitive(nil, nil, nil), newIssueFromTextTestCase("test"))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue