Skip to content

Commit

Permalink
dev: sorts deprecated linters at the end of lists (#4642)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Apr 14, 2024
1 parent 5f9277d commit ad70a88
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pkg/commands/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"fmt"
"slices"
"sort"
"strings"

Expand Down Expand Up @@ -106,8 +107,20 @@ func (c *helpCommand) printPresets() {
}

func printLinters(lcs []*linter.Config) {
sort.Slice(lcs, func(i, j int) bool {
return lcs[i].Name() < lcs[j].Name()
slices.SortFunc(lcs, func(a, b *linter.Config) int {
if a.IsDeprecated() && b.IsDeprecated() {
return strings.Compare(a.Name(), b.Name())
}

if a.IsDeprecated() {
return 1
}

if b.IsDeprecated() {
return -1
}

return strings.Compare(a.Name(), b.Name())
})

for _, lc := range lcs {
Expand Down
17 changes: 17 additions & 0 deletions scripts/website/expand_templates/linters.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"reflect"
"slices"
"sort"
"strings"
"unicode"
Expand Down Expand Up @@ -53,6 +54,22 @@ func getLintersListMarkdown(enabled bool) string {
return neededLcs[i].Name < neededLcs[j].Name
})

slices.SortFunc(neededLcs, func(a, b *types.LinterWrapper) int {
if a.IsDeprecated() && b.IsDeprecated() {
return strings.Compare(a.Name, b.Name)
}

if a.IsDeprecated() {
return 1
}

if b.IsDeprecated() {
return -1
}

return strings.Compare(a.Name, b.Name)
})

lines := []string{
"|Name|Description|Presets|AutoFix|Since|",
"|---|---|---|---|---|---|",
Expand Down
4 changes: 4 additions & 0 deletions scripts/website/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,7 @@ type LinterWrapper struct {
Since string `json:"since,omitempty"`
Deprecation *Deprecation `json:"deprecation,omitempty"`
}

func (l *LinterWrapper) IsDeprecated() bool {
return l.Deprecation != nil
}

0 comments on commit ad70a88

Please sign in to comment.