From d1f642a9dfcdfc97f855c27f447c191c9ded7337 Mon Sep 17 00:00:00 2001 From: Chris Wolf Date: Sat, 19 Feb 2022 11:20:35 -0500 Subject: [PATCH] Sarif results with empty rules now represents as [] instead of null/nil (#786) --- report/sarif.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/report/sarif.go b/report/sarif.go index a8ce2837..0dc0a383 100644 --- a/report/sarif.go +++ b/report/sarif.go @@ -30,13 +30,24 @@ func getRuns(cfg config.Config, findings []Finding) []Runs { } func getTool(cfg config.Config) Tool { - return Tool{ + tool := Tool{ Driver: Driver{ Name: driver, SemanticVersion: version, Rules: getRules(cfg), }, } + + // if this tool has no rules, ensure that it is represented as [] instead of null/nil + if hasEmptyRules(tool) { + tool.Driver.Rules = make([]Rules, 0) + } + + return tool +} + +func hasEmptyRules(tool Tool) bool { + return len(tool.Driver.Rules) == 0 } func getRules(cfg config.Config) []Rules {