1
0
mirror of https://github.com/mgechev/revive.git synced 2025-07-05 00:28:53 +02:00
Files
revive/formatter/json_formatter.go

23 lines
501 B
Go
Raw Normal View History

2017-08-29 10:47:29 -07:00
package formatter
2017-08-27 16:57:16 -07:00
import (
"encoding/json"
2018-01-21 18:04:41 -08:00
"github.com/mgechev/revive/linter"
2017-08-27 16:57:16 -07:00
)
// JSONFormatter is an implementation of the Formatter interface
// which formats the errors to JSON.
type JSONFormatter struct {
2018-01-21 18:04:41 -08:00
Metadata linter.FormatterMetadata
2017-08-27 16:57:16 -07:00
}
// Format formats the failures gotten from the linter.
2018-01-23 17:14:23 -08:00
func (f *JSONFormatter) Format(failures <-chan linter.Failure) (string, error) {
2017-08-27 16:57:16 -07:00
result, error := json.Marshal(failures)
if error != nil {
return "", error
}
return string(result), nil
}