Skip to content

Commit 32df2b0

Browse files
committedJun 16, 2017
fix score error in textdisplay
1 parent 15d8f82 commit 32df2b0

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Install goreporter (see above).
7676
## Run it:
7777

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

8282
- -p Must be a valid Golang project path.

‎tools/report2text.go

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package tools
22

33
import (
4-
"os"
54
"encoding/json"
5+
"os"
66

77
"github.com/fatih/color"
88
"github.com/wgliang/goreporter/engine"
@@ -28,20 +28,25 @@ _/_/ _/
2828
`
2929
metricsHeaderTpl = `>> %s Linter %s find:`
3030
summaryHeaderTpl = ` %s: %s`
31-
errorInfoTpl = ` %s at line %d`
31+
errorInfoTpl = ` %s at line %d`
3232
)
3333

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

39+
var score float64
40+
for _, metric := range structData.Metrics {
41+
score = score + metric.Percentage*metric.Weight
42+
}
43+
3944
color.Magenta(
40-
headerTpl,
41-
structData.Project,
42-
structData.Score,
43-
structData.Grade,
44-
structData.TimeStamp,
45+
headerTpl,
46+
structData.Project,
47+
int(score),
48+
structData.Grade,
49+
structData.TimeStamp,
4550
structData.Issues,
4651
)
4752
for _, metric := range structData.Metrics {
@@ -62,4 +67,4 @@ func DisplayAsText(jsonData []byte) {
6267
} else {
6368
os.Exit(0)
6469
}
65-
}
70+
}

0 commit comments

Comments
 (0)