@@ -25,21 +25,21 @@ const (
2525var _ Processor = (* SortResults )(nil )
2626
2727type SortResults struct {
28- cmps map [string ][] comparator
28+ cmps map [string ]comparator
2929
3030 cfg * config.Output
3131}
3232
3333func NewSortResults (cfg * config.Config ) * SortResults {
3434 return & SortResults {
35- cmps : map [string ][] comparator {
35+ cmps : map [string ]comparator {
3636 // For sorting we are comparing (in next order):
3737 // file names, line numbers, position, and finally - giving up.
38- orderNameFile : { byFileName (), byLine (), byColumn ()} ,
38+ orderNameFile : byFileName (). AddNext ( byLine (). AddNext ( byColumn ())) ,
3939 // For sorting we are comparing: linter name
40- orderNameLinter : { byLinter ()} ,
40+ orderNameLinter : byLinter (),
4141 // For sorting we are comparing: severity
42- orderNameSeverity : { bySeverity ()} ,
42+ orderNameSeverity : bySeverity (),
4343 },
4444 cfg : & cfg .Output ,
4545 }
@@ -58,7 +58,7 @@ func (sr SortResults) Process(issues []result.Issue) ([]result.Issue, error) {
5858 var cmps []comparator
5959 for _ , name := range sr .cfg .SortOrder {
6060 if c , ok := sr .cmps [name ]; ok {
61- cmps = append (cmps , c ... )
61+ cmps = append (cmps , c )
6262 } else {
6363 return nil , fmt .Errorf ("unsupported sort-order name %q" , name )
6464 }
@@ -203,12 +203,20 @@ func mergeComparators(cmps []comparator) (comparator, error) {
203203 }
204204
205205 for i := 0 ; i < len (cmps )- 1 ; i ++ {
206- cmps [i ].AddNext (cmps [i + 1 ])
206+ next ( cmps [i ]) .AddNext (cmps [i + 1 ])
207207 }
208208
209209 return cmps [0 ], nil
210210}
211211
212+ func next (cmp comparator ) comparator {
213+ if cmp .Next () != nil {
214+ return next (cmp .Next ())
215+ }
216+
217+ return cmp
218+ }
219+
212220func severityCompare (a , b string ) compareResult {
213221 // The position inside the slice define the importance (lower to higher).
214222 classic := []string {"low" , "medium" , "high" , "warning" , "error" }
0 commit comments