1
0
mirror of https://github.com/mgechev/revive.git synced 2024-11-28 08:49:11 +02:00
revive/formatter/json.go
2018-02-04 13:42:05 -08:00

32 lines
668 B
Go

package formatter
import (
"encoding/json"
"github.com/mgechev/revive/lint"
)
// JSON is an implementation of the Formatter interface
// which formats the errors to JSON.
type JSON struct {
Metadata lint.FormatterMetadata
}
// Name returns the name of the formatter
func (f *JSON) Name() string {
return "json"
}
// Format formats the failures gotten from the lint.
func (f *JSON) 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
}