Switch to sort Interface to be backward compatible with older go versions

This commit is contained in:
Cosmin Cojocar 2018-02-10 19:45:04 +01:00
parent d4ebb032a9
commit 84bfbbfd8c
2 changed files with 21 additions and 1 deletions

View file

@ -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

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))
}