@@ -25,21 +25,21 @@ const (
25
25
var _ Processor = (* SortResults )(nil )
26
26
27
27
type SortResults struct {
28
- cmps map [string ][] comparator
28
+ cmps map [string ]comparator
29
29
30
30
cfg * config.Output
31
31
}
32
32
33
33
func NewSortResults (cfg * config.Config ) * SortResults {
34
34
return & SortResults {
35
- cmps : map [string ][] comparator {
35
+ cmps : map [string ]comparator {
36
36
// For sorting we are comparing (in next order):
37
37
// file names, line numbers, position, and finally - giving up.
38
- orderNameFile : { byFileName (), byLine (), byColumn ()} ,
38
+ orderNameFile : byFileName (). AddNext ( byLine (). AddNext ( byColumn ())) ,
39
39
// For sorting we are comparing: linter name
40
- orderNameLinter : { byLinter ()} ,
40
+ orderNameLinter : byLinter (),
41
41
// For sorting we are comparing: severity
42
- orderNameSeverity : { bySeverity ()} ,
42
+ orderNameSeverity : bySeverity (),
43
43
},
44
44
cfg : & cfg .Output ,
45
45
}
@@ -58,7 +58,7 @@ func (sr SortResults) Process(issues []result.Issue) ([]result.Issue, error) {
58
58
var cmps []comparator
59
59
for _ , name := range sr .cfg .SortOrder {
60
60
if c , ok := sr .cmps [name ]; ok {
61
- cmps = append (cmps , c ... )
61
+ cmps = append (cmps , c )
62
62
} else {
63
63
return nil , fmt .Errorf ("unsupported sort-order name %q" , name )
64
64
}
@@ -203,12 +203,20 @@ func mergeComparators(cmps []comparator) (comparator, error) {
203
203
}
204
204
205
205
for i := 0 ; i < len (cmps )- 1 ; i ++ {
206
- cmps [i ].AddNext (cmps [i + 1 ])
206
+ findComparatorTip ( cmps [i ]) .AddNext (cmps [i + 1 ])
207
207
}
208
208
209
209
return cmps [0 ], nil
210
210
}
211
211
212
+ func findComparatorTip (cmp comparator ) comparator {
213
+ if cmp .Next () != nil {
214
+ return findComparatorTip (cmp .Next ())
215
+ }
216
+
217
+ return cmp
218
+ }
219
+
212
220
func severityCompare (a , b string ) compareResult {
213
221
// The position inside the slice define the importance (lower to higher).
214
222
classic := []string {"low" , "medium" , "high" , "warning" , "error" }
0 commit comments