From b5f07ea09d24b5ae5d2c76abfcff5330c7e5efb9 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 23 Nov 2024 00:20:08 +0100 Subject: [PATCH 1/4] refactor: use standard comparison values --- pkg/result/processors/sort_results.go | 116 +++++++-------------- pkg/result/processors/sort_results_test.go | 35 ++++--- 2 files changed, 60 insertions(+), 91 deletions(-) diff --git a/pkg/result/processors/sort_results.go b/pkg/result/processors/sort_results.go index 4da73c72ea39..8c3e5c7c06e3 100644 --- a/pkg/result/processors/sort_results.go +++ b/pkg/result/processors/sort_results.go @@ -1,10 +1,10 @@ package processors import ( + "cmp" "errors" "fmt" "slices" - "sort" "strings" "github.com/golangci/golangci-lint/pkg/config" @@ -22,6 +22,12 @@ const ( orderNameSeverity = "severity" ) +const ( + less = iota - 1 + equal + greater +) + var _ Processor = (*SortResults)(nil) type SortResults struct { @@ -67,13 +73,13 @@ func (p SortResults) Process(issues []result.Issue) ([]result.Issue, error) { cmps = append(cmps, c) } - cmp, err := mergeComparators(cmps) + comp, err := mergeComparators(cmps) if err != nil { return nil, err } - sort.Slice(issues, func(i, j int) bool { - return cmp.Compare(&issues[i], &issues[j]) == less + slices.SortFunc(issues, func(a, b result.Issue) int { + return comp.Compare(&a, &b) }) return issues, nil @@ -81,63 +87,36 @@ func (p SortResults) Process(issues []result.Issue) ([]result.Issue, error) { func (SortResults) Finish() {} -type compareResult int - -const ( - less compareResult = iota - 1 - equal - greater - none -) - -func (c compareResult) isNeutral() bool { - // return true if compare result is incomparable or equal. - return c == none || c == equal -} - -func (c compareResult) String() string { - switch c { - case less: - return "less" - case equal: - return "equal" - case greater: - return "greater" - default: - return "none" - } -} - // comparator describes how to implement compare for two "issues". type comparator struct { name string - compare func(a, b *result.Issue) compareResult + compare func(a, b *result.Issue) int next *comparator } -func (cmp *comparator) Next() *comparator { return cmp.next } +func (cp *comparator) Next() *comparator { return cp.next } -func (cmp *comparator) SetNext(c *comparator) *comparator { - cmp.next = c - return cmp +func (cp *comparator) SetNext(c *comparator) *comparator { + cp.next = c + return cp } -func (cmp *comparator) String() string { - s := cmp.name - if cmp.Next() != nil { - s += " > " + cmp.Next().String() +func (cp *comparator) String() string { + s := cp.name + if cp.Next() != nil { + s += " > " + cp.Next().String() } return s } -func (cmp *comparator) Compare(a, b *result.Issue) compareResult { - res := cmp.compare(a, b) - if !res.isNeutral() { +func (cp *comparator) Compare(a, b *result.Issue) int { + res := cp.compare(a, b) + if res != equal { return res } - if next := cmp.Next(); next != nil { + if next := cp.Next(); next != nil { return next.Compare(a, b) } @@ -147,8 +126,8 @@ func (cmp *comparator) Compare(a, b *result.Issue) compareResult { func byFileName() *comparator { return &comparator{ name: "byFileName", - compare: func(a, b *result.Issue) compareResult { - return compareResult(strings.Compare(a.FilePath(), b.FilePath())) + compare: func(a, b *result.Issue) int { + return strings.Compare(a.FilePath(), b.FilePath()) }, } } @@ -156,7 +135,7 @@ func byFileName() *comparator { func byLine() *comparator { return &comparator{ name: "byLine", - compare: func(a, b *result.Issue) compareResult { + compare: func(a, b *result.Issue) int { return numericCompare(a.Line(), b.Line()) }, } @@ -165,7 +144,7 @@ func byLine() *comparator { func byColumn() *comparator { return &comparator{ name: "byColumn", - compare: func(a, b *result.Issue) compareResult { + compare: func(a, b *result.Issue) int { return numericCompare(a.Column(), b.Column()) }, } @@ -174,8 +153,8 @@ func byColumn() *comparator { func byLinter() *comparator { return &comparator{ name: "byLinter", - compare: func(a, b *result.Issue) compareResult { - return compareResult(strings.Compare(a.FromLinter, b.FromLinter)) + compare: func(a, b *result.Issue) int { + return strings.Compare(a.FromLinter, b.FromLinter) }, } } @@ -183,7 +162,7 @@ func byLinter() *comparator { func bySeverity() *comparator { return &comparator{ name: "bySeverity", - compare: func(a, b *result.Issue) compareResult { + compare: func(a, b *result.Issue) int { return severityCompare(a.Severity, b.Severity) }, } @@ -209,19 +188,12 @@ func findComparatorTip(cmp *comparator) *comparator { return cmp } -func severityCompare(a, b string) compareResult { +func severityCompare(a, b string) int { // The position inside the slice define the importance (lower to higher). classic := []string{"low", "medium", "high", "warning", "error"} if slices.Contains(classic, a) && slices.Contains(classic, b) { - switch { - case slices.Index(classic, a) > slices.Index(classic, b): - return greater - case slices.Index(classic, a) < slices.Index(classic, b): - return less - default: - return equal - } + return cmp.Compare(slices.Index(classic, a), slices.Index(classic, b)) } if slices.Contains(classic, a) { @@ -232,28 +204,14 @@ func severityCompare(a, b string) compareResult { return less } - return compareResult(strings.Compare(a, b)) + return strings.Compare(a, b) } -func numericCompare(a, b int) compareResult { - var ( - isValuesInvalid = a < 0 || b < 0 - isZeroValuesBoth = a == 0 && b == 0 - isEqual = a == b - isZeroValueInA = b > 0 && a == 0 - isZeroValueInB = a > 0 && b == 0 - ) - - switch { - case isZeroValuesBoth || isEqual: +func numericCompare(a, b int) int { + // Negative value and 0 are skipped because they either "neutral" (default value) or "invalid. + if a <= 0 || b <= 0 { return equal - case isValuesInvalid || isZeroValueInA || isZeroValueInB: - return none - case a > b: - return greater - case a < b: - return less } - return equal + return cmp.Compare(a, b) } diff --git a/pkg/result/processors/sort_results_test.go b/pkg/result/processors/sort_results_test.go index cc5b32ace543..4917be830a2c 100644 --- a/pkg/result/processors/sort_results_test.go +++ b/pkg/result/processors/sort_results_test.go @@ -73,7 +73,7 @@ var extraSeverityIssues = []result.Issue{ type compareTestCase struct { a, b result.Issue - expected compareResult + expected int } func testCompareValues(t *testing.T, cmp *comparator, name string, tests []compareTestCase) { @@ -82,7 +82,7 @@ func testCompareValues(t *testing.T, cmp *comparator, name string, tests []compa for i, test := range tests { //nolint:gocritic // To ignore rangeValCopy rule t.Run(fmt.Sprintf("%s(%d)", name, i), func(t *testing.T) { res := cmp.Compare(&test.a, &test.b) - assert.Equal(t, test.expected.String(), res.String()) + assert.Equal(t, compToString(test.expected), compToString(res)) }) } } @@ -121,13 +121,13 @@ func TestCompareByFileName(t *testing.T) { func TestCompareByColumn(t *testing.T) { testCompareValues(t, byColumn(), "Compare By Column", []compareTestCase{ {issues[0], issues[1], greater}, // 80 vs 70 - {issues[1], issues[2], none}, // 70 vs zero value + {issues[1], issues[2], equal}, // 70 vs zero value {issues[3], issues[3], equal}, // 60 vs 60 - {issues[2], issues[3], none}, // zero value vs 60 - {issues[2], issues[1], none}, // zero value vs 70 + {issues[2], issues[3], equal}, // zero value vs 60 + {issues[2], issues[1], equal}, // zero value vs 70 {issues[1], issues[0], less}, // 70 vs 80 {issues[1], issues[1], equal}, // 70 vs 70 - {issues[3], issues[2], none}, // vs zero value + {issues[3], issues[2], equal}, // vs zero value {issues[2], issues[2], equal}, // zero value vs zero value {issues[1], issues[1], equal}, // 70 vs 70 }) @@ -185,13 +185,13 @@ func TestCompareNested(t *testing.T) { func TestNumericCompare(t *testing.T) { tests := []struct { a, b int - expected compareResult + expected int }{ {0, 0, equal}, - {0, 1, none}, - {1, 0, none}, - {1, -1, none}, - {-1, 1, none}, + {0, 1, equal}, + {1, 0, equal}, + {1, -1, equal}, + {-1, 1, equal}, {1, 1, equal}, {1, 2, less}, {2, 1, greater}, @@ -202,7 +202,7 @@ func TestNumericCompare(t *testing.T) { for i, test := range tests { t.Run(fmt.Sprintf("%s(%d)", "Numeric Compare", i), func(t *testing.T) { res := numericCompare(test.a, test.b) - assert.Equal(t, test.expected.String(), res.String()) + assert.Equal(t, compToString(test.expected), compToString(res)) }) } } @@ -280,3 +280,14 @@ func Test_mergeComparators_error(t *testing.T) { _, err := mergeComparators(nil) require.EqualError(t, err, "no comparator") } + +func compToString(c int) string { + switch c { + case less: + return "less" + case greater: + return "greater" + default: + return "equal" + } +} From 0e7f721b54431c75061a45b07077df7a1fddfa0a Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 23 Nov 2024 00:59:48 +0100 Subject: [PATCH 2/4] refactor: simplify comparison system --- pkg/result/processors/sort_results.go | 139 ++++++--------------- pkg/result/processors/sort_results_test.go | 106 +++++----------- 2 files changed, 63 insertions(+), 182 deletions(-) diff --git a/pkg/result/processors/sort_results.go b/pkg/result/processors/sort_results.go index 8c3e5c7c06e3..0892d5675c3c 100644 --- a/pkg/result/processors/sort_results.go +++ b/pkg/result/processors/sort_results.go @@ -2,7 +2,6 @@ package processors import ( "cmp" - "errors" "fmt" "slices" "strings" @@ -31,21 +30,21 @@ const ( var _ Processor = (*SortResults)(nil) type SortResults struct { - cmps map[string]*comparator + cmps map[string][]issueComparator cfg *config.Output } func NewSortResults(cfg *config.Config) *SortResults { return &SortResults{ - cmps: map[string]*comparator{ + cmps: map[string][]issueComparator{ // For sorting we are comparing (in next order): // file names, line numbers, position, and finally - giving up. - orderNameFile: byFileName().SetNext(byLine().SetNext(byColumn())), + orderNameFile: {byFileName, byLine, byColumn}, // For sorting we are comparing: linter name - orderNameLinter: byLinter(), + orderNameLinter: {byLinter}, // For sorting we are comparing: severity - orderNameSeverity: bySeverity(), + orderNameSeverity: {bySeverity}, }, cfg: &cfg.Output, } @@ -63,23 +62,21 @@ func (p SortResults) Process(issues []result.Issue) ([]result.Issue, error) { p.cfg.SortOrder = []string{orderNameFile} } - var cmps []*comparator + var cmps []issueComparator + for _, name := range p.cfg.SortOrder { c, ok := p.cmps[name] if !ok { return nil, fmt.Errorf("unsupported sort-order name %q", name) } - cmps = append(cmps, c) + cmps = append(cmps, c...) } - comp, err := mergeComparators(cmps) - if err != nil { - return nil, err - } + comp := mergeComparators(cmps...) slices.SortFunc(issues, func(a, b result.Issue) int { - return comp.Compare(&a, &b) + return comp(&a, &b) }) return issues, nil @@ -87,105 +84,26 @@ func (p SortResults) Process(issues []result.Issue) ([]result.Issue, error) { func (SortResults) Finish() {} -// comparator describes how to implement compare for two "issues". -type comparator struct { - name string - compare func(a, b *result.Issue) int - next *comparator -} - -func (cp *comparator) Next() *comparator { return cp.next } - -func (cp *comparator) SetNext(c *comparator) *comparator { - cp.next = c - return cp -} - -func (cp *comparator) String() string { - s := cp.name - if cp.Next() != nil { - s += " > " + cp.Next().String() - } - - return s -} - -func (cp *comparator) Compare(a, b *result.Issue) int { - res := cp.compare(a, b) - if res != equal { - return res - } - - if next := cp.Next(); next != nil { - return next.Compare(a, b) - } - - return res -} - -func byFileName() *comparator { - return &comparator{ - name: "byFileName", - compare: func(a, b *result.Issue) int { - return strings.Compare(a.FilePath(), b.FilePath()) - }, - } -} - -func byLine() *comparator { - return &comparator{ - name: "byLine", - compare: func(a, b *result.Issue) int { - return numericCompare(a.Line(), b.Line()) - }, - } -} +type issueComparator func(a, b *result.Issue) int -func byColumn() *comparator { - return &comparator{ - name: "byColumn", - compare: func(a, b *result.Issue) int { - return numericCompare(a.Column(), b.Column()) - }, - } +func byFileName(a, b *result.Issue) int { + return strings.Compare(a.FilePath(), b.FilePath()) } -func byLinter() *comparator { - return &comparator{ - name: "byLinter", - compare: func(a, b *result.Issue) int { - return strings.Compare(a.FromLinter, b.FromLinter) - }, - } +func byLine(a, b *result.Issue) int { + return numericCompare(a.Line(), b.Line()) } -func bySeverity() *comparator { - return &comparator{ - name: "bySeverity", - compare: func(a, b *result.Issue) int { - return severityCompare(a.Severity, b.Severity) - }, - } +func byColumn(a, b *result.Issue) int { + return numericCompare(a.Column(), b.Column()) } -func mergeComparators(cmps []*comparator) (*comparator, error) { - if len(cmps) == 0 { - return nil, errors.New("no comparator") - } - - for i := range len(cmps) - 1 { - findComparatorTip(cmps[i]).SetNext(cmps[i+1]) - } - - return cmps[0], nil +func byLinter(a, b *result.Issue) int { + return strings.Compare(a.FromLinter, b.FromLinter) } -func findComparatorTip(cmp *comparator) *comparator { - if cmp.Next() != nil { - return findComparatorTip(cmp.Next()) - } - - return cmp +func bySeverity(a, b *result.Issue) int { + return severityCompare(a.Severity, b.Severity) } func severityCompare(a, b string) int { @@ -208,10 +126,23 @@ func severityCompare(a, b string) int { } func numericCompare(a, b int) int { - // Negative value and 0 are skipped because they either "neutral" (default value) or "invalid. + // Negative values and zeros are skipped (equal) because they either invalid or "neutral" (default int value). if a <= 0 || b <= 0 { return equal } return cmp.Compare(a, b) } + +func mergeComparators(comps ...issueComparator) issueComparator { + return func(a, b *result.Issue) int { + for _, comp := range comps { + i := comp(a, b) + if i != equal { + return i + } + } + + return equal + } +} diff --git a/pkg/result/processors/sort_results_test.go b/pkg/result/processors/sort_results_test.go index 4917be830a2c..153ea7248f56 100644 --- a/pkg/result/processors/sort_results_test.go +++ b/pkg/result/processors/sort_results_test.go @@ -76,19 +76,19 @@ type compareTestCase struct { expected int } -func testCompareValues(t *testing.T, cmp *comparator, name string, tests []compareTestCase) { +func testCompareValues(t *testing.T, cmp issueComparator, name string, tests []compareTestCase) { t.Parallel() for i, test := range tests { //nolint:gocritic // To ignore rangeValCopy rule t.Run(fmt.Sprintf("%s(%d)", name, i), func(t *testing.T) { - res := cmp.Compare(&test.a, &test.b) + res := cmp(&test.a, &test.b) assert.Equal(t, compToString(test.expected), compToString(res)) }) } } -func TestCompareByLine(t *testing.T) { - testCompareValues(t, byLine(), "Compare By Line", []compareTestCase{ +func Test_byLine(t *testing.T) { + testCompareValues(t, byLine, "Compare By Line", []compareTestCase{ {issues[0], issues[1], less}, // 10 vs 11 {issues[0], issues[0], equal}, // 10 vs 10 {issues[3], issues[3], equal}, // 10 vs 10 @@ -103,8 +103,8 @@ func TestCompareByLine(t *testing.T) { }) } -func TestCompareByFileName(t *testing.T) { - testCompareValues(t, byFileName(), "Compare By File Name", []compareTestCase{ +func Test_byFileName(t *testing.T) { + testCompareValues(t, byFileName, "Compare By File Name", []compareTestCase{ {issues[0], issues[1], greater}, // file_windows.go vs file_linux.go {issues[1], issues[2], greater}, // file_linux.go vs file_darwin.go {issues[2], issues[3], equal}, // file_darwin.go vs file_darwin.go @@ -118,8 +118,8 @@ func TestCompareByFileName(t *testing.T) { }) } -func TestCompareByColumn(t *testing.T) { - testCompareValues(t, byColumn(), "Compare By Column", []compareTestCase{ +func Test_byColumn(t *testing.T) { + testCompareValues(t, byColumn, "Compare By Column", []compareTestCase{ {issues[0], issues[1], greater}, // 80 vs 70 {issues[1], issues[2], equal}, // 70 vs zero value {issues[3], issues[3], equal}, // 60 vs 60 @@ -133,8 +133,8 @@ func TestCompareByColumn(t *testing.T) { }) } -func TestCompareByLinter(t *testing.T) { - testCompareValues(t, byLinter(), "Compare By Linter", []compareTestCase{ +func Test_byLinter(t *testing.T) { + testCompareValues(t, byLinter, "Compare By Linter", []compareTestCase{ {issues[0], issues[1], greater}, // b vs a {issues[1], issues[2], less}, // a vs c {issues[2], issues[3], equal}, // c vs c @@ -148,8 +148,8 @@ func TestCompareByLinter(t *testing.T) { }) } -func TestCompareBySeverity(t *testing.T) { - testCompareValues(t, bySeverity(), "Compare By Severity", []compareTestCase{ +func Test_bySeverity(t *testing.T) { + testCompareValues(t, bySeverity, "Compare By Severity", []compareTestCase{ {issues[0], issues[1], greater}, // medium vs low {issues[1], issues[2], less}, // low vs high {issues[2], issues[3], equal}, // high vs high @@ -165,24 +165,24 @@ func TestCompareBySeverity(t *testing.T) { }) } -func TestCompareNested(t *testing.T) { - cmp := byFileName().SetNext(byLine().SetNext(byColumn())) - - testCompareValues(t, cmp, "Nested Comparing", []compareTestCase{ - {issues[1], issues[0], less}, // file_linux.go vs file_windows.go - {issues[2], issues[1], less}, // file_darwin.go vs file_linux.go - {issues[0], issues[1], greater}, // file_windows.go vs file_linux.go - {issues[1], issues[2], greater}, // file_linux.go vs file_darwin.go - {issues[3], issues[2], less}, // file_darwin.go vs file_darwin.go, 10 vs 12 - {issues[0], issues[0], equal}, // file_windows.go vs file_windows.go - {issues[2], issues[3], greater}, // file_darwin.go vs file_darwin.go, 12 vs 10 - {issues[1], issues[1], equal}, // file_linux.go vs file_linux.go - {issues[2], issues[2], equal}, // file_darwin.go vs file_darwin.go - {issues[3], issues[3], equal}, // file_darwin.go vs file_darwin.go - }) +func Test_mergeComparators(t *testing.T) { + testCompareValues(t, mergeComparators(byFileName, byLine, byColumn), "Nested Comparing", + []compareTestCase{ + {issues[1], issues[0], less}, // file_linux.go vs file_windows.go + {issues[2], issues[1], less}, // file_darwin.go vs file_linux.go + {issues[0], issues[1], greater}, // file_windows.go vs file_linux.go + {issues[1], issues[2], greater}, // file_linux.go vs file_darwin.go + {issues[3], issues[2], less}, // file_darwin.go vs file_darwin.go, 10 vs 12 + {issues[0], issues[0], equal}, // file_windows.go vs file_windows.go + {issues[2], issues[3], greater}, // file_darwin.go vs file_darwin.go, 12 vs 10 + {issues[1], issues[1], equal}, // file_linux.go vs file_linux.go + {issues[2], issues[2], equal}, // file_darwin.go vs file_darwin.go + {issues[3], issues[3], equal}, // file_darwin.go vs file_darwin.go + }, + ) } -func TestNumericCompare(t *testing.T) { +func Test_numericCompare(t *testing.T) { tests := []struct { a, b int expected int @@ -231,56 +231,6 @@ func TestSorting(t *testing.T) { assert.Equal(t, []result.Issue{issues[3], issues[2], issues[1], issues[0]}, results) } -func Test_mergeComparators(t *testing.T) { - testCases := []struct { - desc string - cmps []*comparator - expected string - }{ - { - desc: "one", - cmps: []*comparator{byLinter()}, - expected: "byLinter", - }, - { - desc: "two", - cmps: []*comparator{byLinter(), byFileName()}, - expected: "byLinter > byFileName", - }, - { - desc: "all", - cmps: []*comparator{bySeverity(), byLinter(), byFileName(), byLine(), byColumn()}, - expected: "bySeverity > byLinter > byFileName > byLine > byColumn", - }, - { - desc: "nested", - cmps: []*comparator{bySeverity(), byFileName().SetNext(byLine().SetNext(byColumn())), byLinter()}, - expected: "bySeverity > byFileName > byLine > byColumn > byLinter", - }, - { - desc: "all reverse", - cmps: []*comparator{byColumn(), byLine(), byFileName(), byLinter(), bySeverity()}, - expected: "byColumn > byLine > byFileName > byLinter > bySeverity", - }, - } - - for _, test := range testCases { - t.Run(test.desc, func(t *testing.T) { - t.Parallel() - - cmp, err := mergeComparators(test.cmps) - require.NoError(t, err) - - assert.Equal(t, test.expected, cmp.String()) - }) - } -} - -func Test_mergeComparators_error(t *testing.T) { - _, err := mergeComparators(nil) - require.EqualError(t, err, "no comparator") -} - func compToString(c int) string { switch c { case less: From ceb50e3d9da6751da5827c40f2c217ce3e44b89d Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 23 Nov 2024 01:59:32 +0100 Subject: [PATCH 3/4] tests: improve helper --- pkg/result/processors/sort_results_test.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pkg/result/processors/sort_results_test.go b/pkg/result/processors/sort_results_test.go index 153ea7248f56..b2aaa824daee 100644 --- a/pkg/result/processors/sort_results_test.go +++ b/pkg/result/processors/sort_results_test.go @@ -77,11 +77,12 @@ type compareTestCase struct { } func testCompareValues(t *testing.T, cmp issueComparator, name string, tests []compareTestCase) { - t.Parallel() - for i, test := range tests { //nolint:gocritic // To ignore rangeValCopy rule t.Run(fmt.Sprintf("%s(%d)", name, i), func(t *testing.T) { + t.Parallel() + res := cmp(&test.a, &test.b) + assert.Equal(t, compToString(test.expected), compToString(res)) }) } @@ -197,17 +198,18 @@ func Test_numericCompare(t *testing.T) { {2, 1, greater}, } - t.Parallel() - for i, test := range tests { t.Run(fmt.Sprintf("%s(%d)", "Numeric Compare", i), func(t *testing.T) { + t.Parallel() + res := numericCompare(test.a, test.b) + assert.Equal(t, compToString(test.expected), compToString(res)) }) } } -func TestNoSorting(t *testing.T) { +func TestSortResults_Process_noSorting(t *testing.T) { tests := make([]result.Issue, len(issues)) copy(tests, issues) @@ -218,7 +220,7 @@ func TestNoSorting(t *testing.T) { assert.Equal(t, tests, results) } -func TestSorting(t *testing.T) { +func TestSortResults_Process_Sorting(t *testing.T) { tests := make([]result.Issue, len(issues)) copy(tests, issues) @@ -237,7 +239,9 @@ func compToString(c int) string { return "less" case greater: return "greater" - default: + case equal: return "equal" + default: + return "error" } } From e3f8ce8d8d9e4887baf2c2ff23d9e265dd681fae Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 23 Nov 2024 18:03:35 +0100 Subject: [PATCH 4/4] review: move issueComparator --- pkg/result/processors/sort_results.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/result/processors/sort_results.go b/pkg/result/processors/sort_results.go index 0892d5675c3c..7eebea6315ef 100644 --- a/pkg/result/processors/sort_results.go +++ b/pkg/result/processors/sort_results.go @@ -29,6 +29,8 @@ const ( var _ Processor = (*SortResults)(nil) +type issueComparator func(a, b *result.Issue) int + type SortResults struct { cmps map[string][]issueComparator @@ -84,8 +86,6 @@ func (p SortResults) Process(issues []result.Issue) ([]result.Issue, error) { func (SortResults) Finish() {} -type issueComparator func(a, b *result.Issue) int - func byFileName(a, b *result.Issue) int { return strings.Compare(a.FilePath(), b.FilePath()) }