Skip to content

Commit 9b3ba43

Browse files
authored
Added support for only specifying default severity (#1396)
1 parent e4346a8 commit 9b3ba43

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

pkg/result/processors/severity_rules.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func createSeverityRules(rules []SeverityRule, prefix string) []severityRule {
5757
}
5858

5959
func (p SeverityRules) Process(issues []result.Issue) ([]result.Issue, error) {
60-
if len(p.rules) == 0 {
60+
if len(p.rules) == 0 && p.defaultSeverity == "" {
6161
return issues, nil
6262
}
6363
return transformIssues(issues, func(i *result.Issue) *result.Issue {

pkg/result/processors/severity_rules_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,37 @@ func TestSeverityRulesText(t *testing.T) {
132132
assert.Equal(t, texts, processedTexts)
133133
}
134134

135+
func TestSeverityRulesOnlyDefault(t *testing.T) {
136+
lineCache := fsutils.NewLineCache(fsutils.NewFileCache())
137+
log := report.NewLogWrapper(logutils.NewStderrLog(""), &report.Data{})
138+
p := NewSeverityRules("info", []SeverityRule{}, lineCache, log)
139+
140+
cases := []issueTestCase{
141+
{Path: "ssl.go", Text: "ssl", Linter: "gosec"},
142+
{Path: "empty.go", Text: "empty", Linter: "empty"},
143+
}
144+
var issues []result.Issue
145+
for _, c := range cases {
146+
issues = append(issues, newIssueFromIssueTestCase(c))
147+
}
148+
processedIssues := process(t, p, issues...)
149+
var resultingCases []issueTestCase
150+
for _, i := range processedIssues {
151+
resultingCases = append(resultingCases, issueTestCase{
152+
Path: i.FilePath(),
153+
Linter: i.FromLinter,
154+
Text: i.Text,
155+
Line: i.Line(),
156+
Severity: i.Severity,
157+
})
158+
}
159+
expectedCases := []issueTestCase{
160+
{Path: "ssl.go", Text: "ssl", Linter: "gosec", Severity: "info"},
161+
{Path: "empty.go", Text: "empty", Linter: "empty", Severity: "info"},
162+
}
163+
assert.Equal(t, expectedCases, resultingCases)
164+
}
165+
135166
func TestSeverityRulesEmpty(t *testing.T) {
136167
processAssertSame(t, NewSeverityRules("", nil, nil, nil), newIssueFromTextTestCase("test"))
137168
}

0 commit comments

Comments
 (0)