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