fix: sanitize level property for SARIF (#4831)

Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
Zxilly 2024-06-20 06:25:53 +08:00 committed by GitHub
parent 9211eeccf7
commit 304e22a024
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View File

@ -76,7 +76,12 @@ func (p Sarif) Print(issues []result.Issue) error {
issue := issues[i]
severity := issue.Severity
if severity == "" {
switch severity {
// https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/sarif-v2.1.0-errata01-os-complete.html#_Toc141790898
case "none", "note", "warning", "error":
// Valid levels.
default:
severity = "error"
}

View File

@ -42,7 +42,7 @@ func TestSarif_Print(t *testing.T) {
},
{
FromLinter: "linter-a",
Severity: "error",
Severity: "low",
Text: "some issue 2",
Pos: token.Position{
Filename: "path/to/filec.go",