Skip to content

Commit

Permalink
SARIF: Use none for level in notices
Browse files Browse the repository at this point in the history
And don't include notices on deprecated/obsolete rules at all in report.

Fixes #513

Signed-off-by: Anders Eknert <anders@styra.com>
  • Loading branch information
anderseknert committed Dec 5, 2023
1 parent ae00668 commit d664263
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
8 changes: 7 additions & 1 deletion pkg/reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ func (tr SarifReporter) Publish(_ context.Context, r report.Report) error {
}

for _, notice := range r.Notices {
if notice.Severity == "none" {
// no need to report on notices like rules skipped due to
// having been deprecated or made obsolete
continue
}

pb := sarif.NewPropertyBag()
pb.Add("category", notice.Category)

Expand All @@ -369,7 +375,7 @@ func (tr SarifReporter) Publish(_ context.Context, r report.Report) error {

run.CreateResultForRule(notice.Title).
WithKind("informational").
WithLevel(notice.Level).
WithLevel("none").
WithMessage(sarif.NewTextMessage(notice.Description))
}

Expand Down
22 changes: 2 additions & 20 deletions pkg/reporter/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,6 @@ func TestSarifReporterPublish(t *testing.T) {
"category": "really?"
}
},
{
"id": "rule-made-obsolete",
"shortDescription": {
"text": "Rule made obsolete by capability foo"
},
"properties": {
"category": "some-category"
}
},
{
"id": "rule-missing-capability",
"shortDescription": {
Expand Down Expand Up @@ -452,20 +443,11 @@ func TestSarifReporterPublish(t *testing.T) {
}
]
},
{
"ruleId": "rule-made-obsolete",
"ruleIndex": 2,
"kind": "informational",
"level": "notice",
"message": {
"text": "Rule made obsolete by capability foo"
}
},
{
"ruleId": "rule-missing-capability",
"ruleIndex": 3,
"ruleIndex": 2,
"kind": "informational",
"level": "notice",
"level": "none",
"message": {
"text": "Rule missing capability bar"
}
Expand Down

0 comments on commit d664263

Please sign in to comment.