Format formats the lint.Result
(result *lint.Result)
| 16 | |
| 17 | // Format formats the lint.Result |
| 18 | func (f *JSONFormatter) Format(result *lint.Result) (string, error) { |
| 19 | output := make(map[string]interface{}, 4) |
| 20 | |
| 21 | output["input"] = result.Input() |
| 22 | output["issues"] = f.formatIssue(result.Issues()) |
| 23 | |
| 24 | formatted, err := json.Marshal(output) |
| 25 | if err != nil { |
| 26 | return "", fmt.Errorf("json formatting failed: %w", err) |
| 27 | } |
| 28 | return strings.Trim(string(formatted), "\n"), nil |
| 29 | } |
| 30 | |
| 31 | func (f *JSONFormatter) formatIssue(issues []*lint.Issue) []interface{} { |
| 32 | formattedIssues := make([]interface{}, 0, len(issues)) |