Added support for only specifying default severity (#1396)
This commit is contained in:
parent
e4346a8bd6
commit
9b3ba431f1
@ -57,7 +57,7 @@ func createSeverityRules(rules []SeverityRule, prefix string) []severityRule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p SeverityRules) Process(issues []result.Issue) ([]result.Issue, error) {
|
func (p SeverityRules) Process(issues []result.Issue) ([]result.Issue, error) {
|
||||||
if len(p.rules) == 0 {
|
if len(p.rules) == 0 && p.defaultSeverity == "" {
|
||||||
return issues, nil
|
return issues, nil
|
||||||
}
|
}
|
||||||
return transformIssues(issues, func(i *result.Issue) *result.Issue {
|
return transformIssues(issues, func(i *result.Issue) *result.Issue {
|
||||||
|
@ -132,6 +132,37 @@ func TestSeverityRulesText(t *testing.T) {
|
|||||||
assert.Equal(t, texts, processedTexts)
|
assert.Equal(t, texts, processedTexts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSeverityRulesOnlyDefault(t *testing.T) {
|
||||||
|
lineCache := fsutils.NewLineCache(fsutils.NewFileCache())
|
||||||
|
log := report.NewLogWrapper(logutils.NewStderrLog(""), &report.Data{})
|
||||||
|
p := NewSeverityRules("info", []SeverityRule{}, lineCache, log)
|
||||||
|
|
||||||
|
cases := []issueTestCase{
|
||||||
|
{Path: "ssl.go", Text: "ssl", Linter: "gosec"},
|
||||||
|
{Path: "empty.go", Text: "empty", Linter: "empty"},
|
||||||
|
}
|
||||||
|
var issues []result.Issue
|
||||||
|
for _, c := range cases {
|
||||||
|
issues = append(issues, newIssueFromIssueTestCase(c))
|
||||||
|
}
|
||||||
|
processedIssues := process(t, p, issues...)
|
||||||
|
var resultingCases []issueTestCase
|
||||||
|
for _, i := range processedIssues {
|
||||||
|
resultingCases = append(resultingCases, issueTestCase{
|
||||||
|
Path: i.FilePath(),
|
||||||
|
Linter: i.FromLinter,
|
||||||
|
Text: i.Text,
|
||||||
|
Line: i.Line(),
|
||||||
|
Severity: i.Severity,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
expectedCases := []issueTestCase{
|
||||||
|
{Path: "ssl.go", Text: "ssl", Linter: "gosec", Severity: "info"},
|
||||||
|
{Path: "empty.go", Text: "empty", Linter: "empty", Severity: "info"},
|
||||||
|
}
|
||||||
|
assert.Equal(t, expectedCases, resultingCases)
|
||||||
|
}
|
||||||
|
|
||||||
func TestSeverityRulesEmpty(t *testing.T) {
|
func TestSeverityRulesEmpty(t *testing.T) {
|
||||||
processAssertSame(t, NewSeverityRules("", nil, nil, nil), newIssueFromTextTestCase("test"))
|
processAssertSame(t, NewSeverityRules("", nil, nil, nil), newIssueFromTextTestCase("test"))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user