Explorar o código

Sarif results with empty rules now represents as [] instead of null/nil (#786)

Chris Wolf %!s(int64=4) %!d(string=hai) anos
pai
achega
d1f642a9df
Modificáronse 1 ficheiros con 12 adicións e 1 borrados
  1. 12 1
      report/sarif.go

+ 12 - 1
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 {