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-23 18:19:06 -08:00

27 lines
589 B
Go

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