diff --git a/report/json.go b/report/json.go index eb3966e3e..424cb9c2f 100644 --- a/report/json.go +++ b/report/json.go @@ -7,7 +7,7 @@ import ( func writeJson(findings []Finding, w io.WriteCloser) error { if len(findings) == 0 { - return nil + findings = []Finding{} } encoder := json.NewEncoder(w) encoder.SetIndent("", " ") diff --git a/report/json_test.go b/report/json_test.go index 79a0229b6..d20cf86bf 100644 --- a/report/json_test.go +++ b/report/json_test.go @@ -39,9 +39,8 @@ func TestWriteJSON(t *testing.T) { }}, { - wantEmpty: true, testReportName: "empty", - expected: filepath.Join(expectPath, "report", "this_should_not_exist.json"), + expected: filepath.Join(expectPath, "report", "empty.json"), findings: []Finding{}}, } diff --git a/report/report.go b/report/report.go index 8393c8149..42bdac6f5 100644 --- a/report/report.go +++ b/report/report.go @@ -14,9 +14,6 @@ const ( ) func Write(findings []Finding, cfg config.Config, ext string, reportPath string) error { - if len(findings) == 0 { - return nil - } file, err := os.Create(reportPath) if err != nil { return err diff --git a/testdata/expected/report/empty.json b/testdata/expected/report/empty.json new file mode 100644 index 000000000..fe51488c7 --- /dev/null +++ b/testdata/expected/report/empty.json @@ -0,0 +1 @@ +[]