2021-11-14 20:01:54 +00:00
|
|
|
package printers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
2022-02-24 16:33:24 +00:00
|
|
|
"io"
|
2021-11-14 20:01:54 +00:00
|
|
|
|
|
|
|
"github.com/golangci/golangci-lint/pkg/report"
|
|
|
|
"github.com/golangci/golangci-lint/pkg/result"
|
|
|
|
)
|
|
|
|
|
|
|
|
type JSON struct {
|
|
|
|
rd *report.Data
|
2022-02-24 16:33:24 +00:00
|
|
|
w io.Writer
|
2021-11-14 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2022-02-24 16:33:24 +00:00
|
|
|
func NewJSON(rd *report.Data, w io.Writer) *JSON {
|
2021-11-14 20:01:54 +00:00
|
|
|
return &JSON{
|
|
|
|
rd: rd,
|
2022-02-24 16:33:24 +00:00
|
|
|
w: w,
|
2021-11-14 20:01:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type JSONResult struct {
|
|
|
|
Issues []result.Issue
|
|
|
|
Report *report.Data
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p JSON) Print(ctx context.Context, issues []result.Issue) error {
|
|
|
|
res := JSONResult{
|
|
|
|
Issues: issues,
|
|
|
|
Report: p.rd,
|
|
|
|
}
|
2022-02-24 16:33:24 +00:00
|
|
|
if res.Issues == nil {
|
|
|
|
res.Issues = []result.Issue{}
|
2021-11-14 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
2022-02-24 16:33:24 +00:00
|
|
|
return json.NewEncoder(p.w).Encode(res)
|
2021-11-14 20:01:54 +00:00
|
|
|
}
|