mirror of
https://github.com/gojp/goreportcard.git
synced 2026-01-28 22:39:05 +08:00
Adjust and normalize weights, andd add errcheck to checks in handlers
This commit is contained in:
@@ -13,7 +13,7 @@ func (g GoVet) Name() string {
|
||||
|
||||
// Weight returns the weight this check has in the overall average
|
||||
func (g GoVet) Weight() float64 {
|
||||
return .35
|
||||
return .25
|
||||
}
|
||||
|
||||
// Percentage returns the percentage of .go files that pass go vet
|
||||
|
||||
@@ -13,7 +13,7 @@ func (g GoCyclo) Name() string {
|
||||
|
||||
// Weight returns the weight this check has in the overall average
|
||||
func (g GoCyclo) Weight() float64 {
|
||||
return .05
|
||||
return .10
|
||||
}
|
||||
|
||||
// Percentage returns the percentage of .go files that pass gofmt
|
||||
|
||||
@@ -13,7 +13,7 @@ func (g GoFmt) Name() string {
|
||||
|
||||
// Weight returns the weight this check has in the overall average
|
||||
func (g GoFmt) Weight() float64 {
|
||||
return .40
|
||||
return .30
|
||||
}
|
||||
|
||||
// Percentage returns the percentage of .go files that pass gofmt
|
||||
|
||||
@@ -13,7 +13,7 @@ func (g IneffAssign) Name() string {
|
||||
|
||||
// Weight returns the weight this check has in the overall average
|
||||
func (g IneffAssign) Weight() float64 {
|
||||
return 0.0
|
||||
return 0.05
|
||||
}
|
||||
|
||||
// Percentage returns the percentage of .go files that pass gofmt
|
||||
|
||||
@@ -19,7 +19,7 @@ func (g License) Name() string {
|
||||
|
||||
// Weight returns the weight this check has in the overall average
|
||||
func (g License) Weight() float64 {
|
||||
return .10
|
||||
return .05
|
||||
}
|
||||
|
||||
// thank you https://github.com/ryanuber/go-license and client9
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
"github.com/dustin/go-humanize"
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/gojp/goreportcard/check"
|
||||
)
|
||||
|
||||
@@ -185,6 +185,7 @@ func newChecksResp(repo string, forceRefresh bool) (checksResp, error) {
|
||||
check.License{Dir: dir, Filenames: []string{}},
|
||||
check.Misspell{Dir: dir, Filenames: filenames},
|
||||
check.IneffAssign{Dir: dir, Filenames: filenames},
|
||||
check.ErrCheck{Dir: dir, Filenames: filenames},
|
||||
}
|
||||
|
||||
ch := make(chan score)
|
||||
@@ -213,17 +214,20 @@ func newChecksResp(repo string, forceRefresh bool) (checksResp, error) {
|
||||
}
|
||||
|
||||
var total float64
|
||||
var totalWeight float64
|
||||
var issues = make(map[string]bool)
|
||||
for i := 0; i < len(checks); i++ {
|
||||
s := <-ch
|
||||
resp.Checks = append(resp.Checks, s)
|
||||
total += s.Percentage * s.Weight
|
||||
totalWeight += s.Weight
|
||||
for _, fs := range s.FileSummaries {
|
||||
issues[fs.Filename] = true
|
||||
}
|
||||
}
|
||||
total /= totalWeight
|
||||
|
||||
sort.Sort(ByName(resp.Checks))
|
||||
sort.Sort(ByWeight(resp.Checks))
|
||||
resp.Average = total
|
||||
resp.Issues = len(issues)
|
||||
resp.Grade = grade(total * 100)
|
||||
@@ -231,9 +235,9 @@ func newChecksResp(repo string, forceRefresh bool) (checksResp, error) {
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// ByName implements sorting for checks alphabetically by name
|
||||
type ByName []score
|
||||
// ByWeight implements sorting for checks by weight descending
|
||||
type ByWeight []score
|
||||
|
||||
func (a ByName) Len() int { return len(a) }
|
||||
func (a ByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a ByName) Less(i, j int) bool { return a[i].Name < a[j].Name }
|
||||
func (a ByWeight) Len() int { return len(a) }
|
||||
func (a ByWeight) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a ByWeight) Less(i, j int) bool { return a[i].Weight > a[j].Weight }
|
||||
|
||||
Reference in New Issue
Block a user