| 53 | } |
| 54 | |
| 55 | func TestJSONFormatter_EmptyViolations(t *testing.T) { |
| 56 | out := new(bytes.Buffer) |
| 57 | formatter := JSONFormatter{out: out} |
| 58 | |
| 59 | var violations []struct { |
| 60 | Rule string `json:"rule"` |
| 61 | Violation string `json:"violation"` |
| 62 | FileName string `json:"file_name"` |
| 63 | LineNumber int `json:"line_number"` |
| 64 | } |
| 65 | |
| 66 | formatter.Format(rules.RuleViolationList{}) |
| 67 | |
| 68 | err := json.Unmarshal(out.Bytes(), &violations) |
| 69 | require.NoError(t, err, "output should be valid JSON even with no violations") |
| 70 | assert.Equal(t, 0, len(violations), "should have empty array for no violations") |
| 71 | } |