1
0
mirror of https://github.com/mgechev/revive.git synced 2024-11-28 08:49:11 +02:00

Update formatters

This commit is contained in:
mgechev 2018-01-23 18:19:06 -08:00
parent 5c6de19f89
commit 25cfe541d2
6 changed files with 13 additions and 8 deletions

View File

@ -37,6 +37,7 @@ func (f *CLIFormatter) Format(failures <-chan linter.Failure) (string, error) {
var result [][]string
var totalErrors = 0
var total = 0
for f := range failures {
result = append(result, formatFailure(f))
total++

View File

@ -14,9 +14,13 @@ type JSONFormatter struct {
// Format formats the failures gotten from the linter.
func (f *JSONFormatter) Format(failures <-chan linter.Failure) (string, error) {
result, error := json.Marshal(failures)
if error != nil {
return "", error
var slice []linter.Failure
for failure := range failures {
slice = append(slice, failure)
}
return string(result), nil
result, err := json.Marshal(slice)
if err != nil {
return "", err
}
return string(result), err
}

View File

@ -4,4 +4,4 @@ import:
- package: github.com/mattn/go-runewidth
version: ~0.0.2
- package: github.com/fatih/color
version: ~1.5.0
version: ~1.5.0

View File

@ -9,5 +9,5 @@ type FormatterMetadata struct {
// Formatter defines an interface for failure formatters
type Formatter interface {
Format(<-chan Failure) string
Format(<-chan Failure, <-chan string, int) string
}

View File

@ -28,7 +28,7 @@ type Failure struct {
Category string
Type FailureType
Position FailurePosition
Node ast.Node
Node ast.Node `json:"-"`
Confidence float64
}

View File

@ -40,7 +40,7 @@ func main() {
panic(err)
}
var formatter formatter.CLIFormatter
var formatter formatter.JSONFormatter
output, err := formatter.Format(failures)
if err != nil {
panic(err)