Skip to content

Commit 777b706

Browse files
authored
Merge pull request #167 from cosmincojocar/sort_by_severity
Sort the issues by severity in descending order
2 parents 6b28d5c + e15c057 commit 777b706

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ language: go
22
before_script:
33
- go vet $(go list ./... | grep -v /vendor/)
44
go:
5-
- 1.5
5+
- 1.7
6+
- 1.8
7+
- 1.9
68
- tip
79
install:
810
- go get -v github.com/onsi/ginkgo/ginkgo

cmd/gas/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ var (
7979
// log to file or stderr
8080
flagLogfile = flag.String("log", "", "Log messages to file rather than stderr")
8181

82+
// sort the issues by severity
83+
flagSortIssues = flag.Bool("sort", true, "Sort issues by severity")
84+
8285
logger *log.Logger
8386
)
8487

@@ -231,6 +234,11 @@ func main() {
231234
os.Exit(0)
232235
}
233236

237+
// Sort the issue by severity
238+
if *flagSortIssues {
239+
sortIssues(issues)
240+
}
241+
234242
// Create output report
235243
if err := saveOutput(*flagOutput, *flagFormat, issues, metrics); err != nil {
236244
logger.Fatal(err)

cmd/gas/sort_issues.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package main
2+
3+
import (
4+
"sort"
5+
6+
"github.com/GoASTScanner/gas"
7+
)
8+
9+
type sortBySeverity []*gas.Issue
10+
11+
func (s sortBySeverity) Len() int { return len(s) }
12+
13+
func (s sortBySeverity) Less(i, j int) bool { return s[i].Severity > s[i].Severity }
14+
15+
func (s sortBySeverity) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
16+
17+
// sortIssues sorts the issues by severity in descending order
18+
func sortIssues(issues []*gas.Issue) {
19+
sort.Sort(sortBySeverity(issues))
20+
}

0 commit comments

Comments
 (0)