Skip to content

Commit 812cee7

Browse files
committed
chore: use nesting instead of slice
1 parent 6963aef commit 812cee7

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

pkg/result/processors/sort_results.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ const (
2525
var _ Processor = (*SortResults)(nil)
2626

2727
type SortResults struct {
28-
cmps map[string][]comparator
28+
cmps map[string]comparator
2929

3030
cfg *config.Output
3131
}
3232

3333
func 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
}

pkg/result/processors/sort_results_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ func Test_mergeComparators(t *testing.T) {
254254
cmps: []comparator{bySeverity(), byLinter(), byFileName(), byLine(), byColumn()},
255255
expected: "bySeverity > byLinter > byFileName > byLine > byColumn",
256256
},
257+
{
258+
desc: "nested",
259+
cmps: []comparator{bySeverity(), byLinter(), byFileName().AddNext(byLine().AddNext(byColumn()))},
260+
expected: "bySeverity > byLinter > byFileName > byLine > byColumn",
261+
},
257262
{
258263
desc: "all reverse",
259264
cmps: []comparator{byColumn(), byLine(), byFileName(), byLinter(), bySeverity()},

0 commit comments

Comments
 (0)