From d664263204e36461d64832e5364fd49f92a9d897 Mon Sep 17 00:00:00 2001 From: Anders Eknert Date: Tue, 5 Dec 2023 21:20:47 +0100 Subject: [PATCH] SARIF: Use `none` for `level` in notices And don't include notices on deprecated/obsolete rules at all in report. Fixes #513 Signed-off-by: Anders Eknert --- pkg/reporter/reporter.go | 8 +++++++- pkg/reporter/reporter_test.go | 22 ++-------------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/pkg/reporter/reporter.go b/pkg/reporter/reporter.go index 90f3bb51..b9a76a2f 100644 --- a/pkg/reporter/reporter.go +++ b/pkg/reporter/reporter.go @@ -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) @@ -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)) } diff --git a/pkg/reporter/reporter_test.go b/pkg/reporter/reporter_test.go index 284568c7..cef3eee0 100644 --- a/pkg/reporter/reporter_test.go +++ b/pkg/reporter/reporter_test.go @@ -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": { @@ -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" }