From d4ebb032a9e3abd0af263b15b6355c636d1db363 Mon Sep 17 00:00:00 2001 From: Cosmin Cojocar Date: Thu, 8 Feb 2018 12:08:05 +0100 Subject: [PATCH 1/3] Sort the issues by severity in descending order before creating the report --- cmd/gas/main.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/cmd/gas/main.go b/cmd/gas/main.go index 80208ea..bfbe676 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 { + sort.Slice(issues, func(i, j int) bool { return (issues[i].Severity > issues[j].Severity) }) + } + // Create output report if err := saveOutput(*flagOutput, *flagFormat, issues, metrics); err != nil { logger.Fatal(err) From 84bfbbfd8c8867536218ab5b096d8790cbb36a88 Mon Sep 17 00:00:00 2001 From: Cosmin Cojocar Date: Sat, 10 Feb 2018 19:45:04 +0100 Subject: [PATCH 2/3] Switch to sort Interface to be backward compatible with older go versions --- cmd/gas/main.go | 2 +- cmd/gas/sort_issues.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 cmd/gas/sort_issues.go diff --git a/cmd/gas/main.go b/cmd/gas/main.go index bfbe676..03dc30c 100644 --- a/cmd/gas/main.go +++ b/cmd/gas/main.go @@ -236,7 +236,7 @@ func main() { // Sort the issue by severity if *flagSortIssues { - sort.Slice(issues, func(i, j int) bool { return (issues[i].Severity > issues[j].Severity) }) + sortIssues(issues) } // Create output report 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)) +} From e15c057349dd08da4de85dac639f30c682bcb14d Mon Sep 17 00:00:00 2001 From: Cosmin Cojocar Date: Sat, 10 Feb 2018 19:46:39 +0100 Subject: [PATCH 3/3] Update the build file to validate gas from go version 1.7 onward --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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