Skip to content

Commit ad70a88

Browse files
authored
dev: sorts deprecated linters at the end of lists (#4642)
1 parent 5f9277d commit ad70a88

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

pkg/commands/help.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package commands
22

33
import (
44
"fmt"
5+
"slices"
56
"sort"
67
"strings"
78

@@ -106,8 +107,20 @@ func (c *helpCommand) printPresets() {
106107
}
107108

108109
func printLinters(lcs []*linter.Config) {
109-
sort.Slice(lcs, func(i, j int) bool {
110-
return lcs[i].Name() < lcs[j].Name()
110+
slices.SortFunc(lcs, func(a, b *linter.Config) int {
111+
if a.IsDeprecated() && b.IsDeprecated() {
112+
return strings.Compare(a.Name(), b.Name())
113+
}
114+
115+
if a.IsDeprecated() {
116+
return 1
117+
}
118+
119+
if b.IsDeprecated() {
120+
return -1
121+
}
122+
123+
return strings.Compare(a.Name(), b.Name())
111124
})
112125

113126
for _, lc := range lcs {

scripts/website/expand_templates/linters.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"path/filepath"
77
"reflect"
8+
"slices"
89
"sort"
910
"strings"
1011
"unicode"
@@ -53,6 +54,22 @@ func getLintersListMarkdown(enabled bool) string {
5354
return neededLcs[i].Name < neededLcs[j].Name
5455
})
5556

57+
slices.SortFunc(neededLcs, func(a, b *types.LinterWrapper) int {
58+
if a.IsDeprecated() && b.IsDeprecated() {
59+
return strings.Compare(a.Name, b.Name)
60+
}
61+
62+
if a.IsDeprecated() {
63+
return 1
64+
}
65+
66+
if b.IsDeprecated() {
67+
return -1
68+
}
69+
70+
return strings.Compare(a.Name, b.Name)
71+
})
72+
5673
lines := []string{
5774
"|Name|Description|Presets|AutoFix|Since|",
5875
"|---|---|---|---|---|---|",

scripts/website/types/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@ type LinterWrapper struct {
4545
Since string `json:"since,omitempty"`
4646
Deprecation *Deprecation `json:"deprecation,omitempty"`
4747
}
48+
49+
func (l *LinterWrapper) IsDeprecated() bool {
50+
return l.Deprecation != nil
51+
}

0 commit comments

Comments
 (0)