Merge pull request #167 from cosmincojocar/sort_by_severity

Sort the issues by severity in descending order
This commit is contained in:
Grant Murphy 2018-02-11 22:29:45 +10:00 committed by GitHub
commit 777b706a2a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 1 deletions

View file

@ -2,7 +2,9 @@ language: go
before_script: before_script:
- go vet $(go list ./... | grep -v /vendor/) - go vet $(go list ./... | grep -v /vendor/)
go: go:
- 1.5 - 1.7
- 1.8
- 1.9
- tip - tip
install: install:
- go get -v github.com/onsi/ginkgo/ginkgo - go get -v github.com/onsi/ginkgo/ginkgo

View file

@ -79,6 +79,9 @@ var (
// log to file or stderr // log to file or stderr
flagLogfile = flag.String("log", "", "Log messages to file rather than stderr") flagLogfile = flag.String("log", "", "Log messages to file rather than stderr")
// sort the issues by severity
flagSortIssues = flag.Bool("sort", true, "Sort issues by severity")
logger *log.Logger logger *log.Logger
) )
@ -231,6 +234,11 @@ func main() {
os.Exit(0) os.Exit(0)
} }
// Sort the issue by severity
if *flagSortIssues {
sortIssues(issues)
}
// Create output report // Create output report
if err := saveOutput(*flagOutput, *flagFormat, issues, metrics); err != nil { if err := saveOutput(*flagOutput, *flagFormat, issues, metrics); err != nil {
logger.Fatal(err) logger.Fatal(err)

20
cmd/gas/sort_issues.go Normal file
View file

@ -0,0 +1,20 @@
package main
import (
"sort"
"github.com/GoASTScanner/gas"
)
type sortBySeverity []*gas.Issue
func (s sortBySeverity) Len() int { return len(s) }
func (s sortBySeverity) Less(i, j int) bool { return s[i].Severity > s[i].Severity }
func (s sortBySeverity) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
// sortIssues sorts the issues by severity in descending order
func sortIssues(issues []*gas.Issue) {
sort.Sort(sortBySeverity(issues))
}