mirror of
https://github.com/mgechev/revive.git
synced 2024-11-24 08:32:22 +02:00
23 lines
496 B
Go
23 lines
496 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 []linter.Failure) (string, error) {
|
|
result, error := json.Marshal(failures)
|
|
if error != nil {
|
|
return "", error
|
|
}
|
|
return string(result), nil
|
|
}
|