MCPcopy Create free account
hub / github.com/checkmake/checkmake / Format

Method Format

formatters/json.go:22–48  ·  view source on GitHub ↗

Format is the function to call to get the formatted JSON output

(violations rules.RuleViolationList)

Source from the content-addressed store, hash-verified

20
21// Format is the function to call to get the formatted JSON output
22func (f *JSONFormatter) Format(violations rules.RuleViolationList) {
23 // Convert violations to JSON-serializable structure
24 type ViolationJSON struct {
25 Rule string `json:"rule"`
26 Violation string `json:"violation"`
27 FileName string `json:"file_name"`
28 LineNumber int `json:"line_number"`
29 }
30
31 violationsJSON := make([]ViolationJSON, len(violations))
32 for i, v := range violations {
33 violationsJSON[i] = ViolationJSON{
34 Rule: v.Rule,
35 Violation: v.Violation,
36 FileName: v.FileName,
37 LineNumber: v.LineNumber,
38 }
39 }
40
41 encoder := json.NewEncoder(f.out)
42 encoder.SetIndent("", " ")
43 if err := encoder.Encode(violationsJSON); err != nil {
44 // If encoding fails, we can't really recover, so we'll just return
45 // The error will be visible in the output stream
46 return
47 }
48}

Callers 2

TestJSONFormatterFunction · 0.95

Calls

no outgoing calls

Tested by 2

TestJSONFormatterFunction · 0.76