Skip to content

Commit

Permalink
fix score error in textdisplay
Browse files Browse the repository at this point in the history
  • Loading branch information
wgliang committed Jun 16, 2017
1 parent 15d8f82 commit 32df2b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Install goreporter (see above).
## Run it:

```
$ goreporter -p [projectRelativePath] -r [reportPath] -e [exceptPackagesName] -f [json/html] {-t templatePathIfHtml}
$ goreporter -p [projectRelativePath] -r [reportPath] -e [exceptPackagesName] -f [json/html/text] {-t templatePathIfHtml}
```

- -p Must be a valid Golang project path.
Expand Down
21 changes: 13 additions & 8 deletions tools/report2text.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package tools

import (
"os"
"encoding/json"
"os"

"github.com/fatih/color"
"github.com/wgliang/goreporter/engine"
Expand All @@ -28,20 +28,25 @@ _/_/ _/
`
metricsHeaderTpl = `>> %s Linter %s find:`
summaryHeaderTpl = ` %s: %s`
errorInfoTpl = ` %s at line %d`
errorInfoTpl = ` %s at line %d`
)

// DisplayAsText will display the json data to console
func DisplayAsText(jsonData []byte) {
var structData engine.Reporter
json.Unmarshal(jsonData, &structData)

var score float64
for _, metric := range structData.Metrics {
score = score + metric.Percentage*metric.Weight
}

color.Magenta(
headerTpl,
structData.Project,
structData.Score,
structData.Grade,
structData.TimeStamp,
headerTpl,
structData.Project,
int(score),
structData.Grade,
structData.TimeStamp,
structData.Issues,
)
for _, metric := range structData.Metrics {
Expand All @@ -62,4 +67,4 @@ func DisplayAsText(jsonData []byte) {
} else {
os.Exit(0)
}
}
}

0 comments on commit 32df2b0

Please sign in to comment.