From 25cfe541d2097888aba0f3b7def78d88a419ea10 Mon Sep 17 00:00:00 2001 From: mgechev Date: Tue, 23 Jan 2018 18:19:06 -0800 Subject: [PATCH] Update formatters --- formatter/cli_formatter.go | 1 + formatter/json_formatter.go | 12 ++++++++---- glide.yaml | 2 +- linter/formatter.go | 2 +- linter/rule.go | 2 +- main.go | 2 +- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/formatter/cli_formatter.go b/formatter/cli_formatter.go index 432efa8..a355b18 100644 --- a/formatter/cli_formatter.go +++ b/formatter/cli_formatter.go @@ -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++ diff --git a/formatter/json_formatter.go b/formatter/json_formatter.go index 1d7e70d..3ddb1ab 100644 --- a/formatter/json_formatter.go +++ b/formatter/json_formatter.go @@ -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 } diff --git a/glide.yaml b/glide.yaml index 4fa8405..6e97753 100644 --- a/glide.yaml +++ b/glide.yaml @@ -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 \ No newline at end of file diff --git a/linter/formatter.go b/linter/formatter.go index d30522f..c249c5f 100644 --- a/linter/formatter.go +++ b/linter/formatter.go @@ -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 } diff --git a/linter/rule.go b/linter/rule.go index 31023c2..ff52b96 100644 --- a/linter/rule.go +++ b/linter/rule.go @@ -28,7 +28,7 @@ type Failure struct { Category string Type FailureType Position FailurePosition - Node ast.Node + Node ast.Node `json:"-"` Confidence float64 } diff --git a/main.go b/main.go index 7ae7c22..f0f4b43 100644 --- a/main.go +++ b/main.go @@ -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)