diff --git a/.travis.yml b/.travis.yml index 37924cd..d14b1cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,9 @@ language: go before_script: - go vet $(go list ./... | grep -v /vendor/) go: - - 1.5 + - 1.7 + - 1.8 + - 1.9 - tip install: - go get -v github.com/onsi/ginkgo/ginkgo diff --git a/cmd/gas/main.go b/cmd/gas/main.go index 80208ea..03dc30c 100644 --- a/cmd/gas/main.go +++ b/cmd/gas/main.go @@ -79,6 +79,9 @@ var ( // log to file or 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 ) @@ -231,6 +234,11 @@ func main() { os.Exit(0) } + // Sort the issue by severity + if *flagSortIssues { + sortIssues(issues) + } + // Create output report if err := saveOutput(*flagOutput, *flagFormat, issues, metrics); err != nil { logger.Fatal(err) diff --git a/cmd/gas/sort_issues.go b/cmd/gas/sort_issues.go new file mode 100644 index 0000000..5557f96 --- /dev/null +++ b/cmd/gas/sort_issues.go @@ -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)) +}