1
0
mirror of https://github.com/mgechev/revive.git synced 2025-03-19 21:07:46 +02:00
revive/formatter/json_formatter.go
2018-01-24 15:44:03 -08:00

27 lines
604 B
Go

package formatter
import (
"encoding/json"
"github.com/mgechev/revive/lint"
)
// JSONFormatter is an implementation of the Formatter interface
// which formats the errors to JSON.
type JSONFormatter struct {
Metadata lint.FormatterMetadata
}
// Format formats the failures gotten from the lint.
func (f *JSONFormatter) Format(failures <-chan lint.Failure, config lint.RulesConfig) (string, error) {
var slice []lint.Failure
for failure := range failures {
slice = append(slice, failure)
}
result, err := json.Marshal(slice)
if err != nil {
return "", err
}
return string(result), err
}