diff --git a/check/check.go b/check/check.go index 4bf749a..1ead40a 100644 --- a/check/check.go +++ b/check/check.go @@ -5,6 +5,7 @@ package check type Check interface { Name() string Description() string + Weight() float64 // Percentage returns the passing percentage of the check, // as well as a map of filename to output Percentage() (float64, []FileSummary, error) diff --git a/check/go_vet.go b/check/go_vet.go index 884a196..6ec4f00 100644 --- a/check/go_vet.go +++ b/check/go_vet.go @@ -11,6 +11,11 @@ func (g GoVet) Name() string { return "go_vet" } +// Weight returns the weight this check has in the overall average +func (g GoVet) Weight() float64 { + return .225 +} + // Percentage returns the percentage of .go files that pass go vet func (g GoVet) Percentage() (float64, []FileSummary, error) { return GoTool(g.Dir, g.Filenames, []string{"go", "tool", "vet"}) diff --git a/check/gocyclo.go b/check/gocyclo.go index aaaaa4a..05569b1 100644 --- a/check/gocyclo.go +++ b/check/gocyclo.go @@ -11,6 +11,11 @@ func (g GoCyclo) Name() string { return "gocyclo" } +// Weight returns the weight this check has in the overall average +func (g GoCyclo) Weight() float64 { + return .225 +} + // Percentage returns the percentage of .go files that pass gofmt func (g GoCyclo) Percentage() (float64, []FileSummary, error) { return GoTool(g.Dir, g.Filenames, []string{"gocyclo", "-over", "15"}) diff --git a/check/gofmt.go b/check/gofmt.go index b1451fa..a2fe803 100644 --- a/check/gofmt.go +++ b/check/gofmt.go @@ -11,6 +11,11 @@ func (g GoFmt) Name() string { return "gofmt" } +// Weight returns the weight this check has in the overall average +func (g GoFmt) Weight() float64 { + return .225 +} + // Percentage returns the percentage of .go files that pass gofmt func (g GoFmt) Percentage() (float64, []FileSummary, error) { return GoTool(g.Dir, g.Filenames, []string{"gofmt", "-s", "-l"}) diff --git a/check/golint.go b/check/golint.go index 7c7df8a..0f44746 100644 --- a/check/golint.go +++ b/check/golint.go @@ -11,6 +11,11 @@ func (g GoLint) Name() string { return "golint" } +// Weight returns the weight this check has in the overall average +func (g GoLint) Weight() float64 { + return .225 +} + // Percentage returns the percentage of .go files that pass golint func (g GoLint) Percentage() (float64, []FileSummary, error) { return GoTool(g.Dir, g.Filenames, []string{"golint"}) diff --git a/check/license.go b/check/license.go index 0c02db4..d99d46c 100644 --- a/check/license.go +++ b/check/license.go @@ -16,7 +16,12 @@ func (g License) Name() string { return "license" } -// Percentage returns 0 if no LICENSE, 100 if LICENSE +// Weight returns the weight this check has in the overall average +func (g License) Weight() float64 { + return .1 +} + +// Percentage returns 0 if no LICENSE, 1 if LICENSE func (g License) Percentage() (float64, []FileSummary, error) { cmd := exec.Command("find", g.Dir, "-maxdepth", "1", "-type", "f", "-name", "LICENSE") var out bytes.Buffer @@ -29,7 +34,7 @@ func (g License) Percentage() (float64, []FileSummary, error) { return 0.0, []FileSummary{{"", "http://choosealicense.com/", []Error{}}}, nil } - return 100.0, []FileSummary{}, nil + return 1.0, []FileSummary{}, nil } // Description returns the description of License diff --git a/handlers/checks.go b/handlers/checks.go index c9975cf..cef0737 100644 --- a/handlers/checks.go +++ b/handlers/checks.go @@ -42,6 +42,7 @@ type score struct { Name string `json:"name"` Description string `json:"description"` FileSummaries []check.FileSummary `json:"file_summaries"` + Weight float64 `json:"weight"` Percentage float64 `json:"percentage"` } @@ -128,7 +129,8 @@ func newChecksResp(repo string, forceRefresh bool) (checksResp, error) { if len(filenames) == 0 { return checksResp{}, fmt.Errorf("No .go files found") } - checks := []check.Check{check.GoFmt{Dir: dir, Filenames: filenames}, + checks := []check.Check{ + check.GoFmt{Dir: dir, Filenames: filenames}, check.GoVet{Dir: dir, Filenames: filenames}, check.GoLint{Dir: dir, Filenames: filenames}, check.GoCyclo{Dir: dir, Filenames: filenames}, @@ -146,6 +148,7 @@ func newChecksResp(repo string, forceRefresh bool) (checksResp, error) { Name: c.Name(), Description: c.Description(), FileSummaries: summaries, + Weight: c.Weight(), Percentage: p, } ch <- s @@ -160,15 +163,15 @@ func newChecksResp(repo string, forceRefresh bool) (checksResp, error) { for i := 0; i < len(checks); i++ { s := <-ch resp.Checks = append(resp.Checks, s) - total += s.Percentage + total += s.Percentage * s.Weight for _, fs := range s.FileSummaries { issues[fs.Filename] = true } } - resp.Average = total / float64(len(checks)) + resp.Average = total resp.Issues = len(issues) - resp.Grade = grade(resp.Average * 100) + resp.Grade = grade(total * 100) return resp, nil }