From ad70a8884b45d9cd6de38626a4aa65dbf9c8aa31 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Sun, 14 Apr 2024 14:40:04 +0200 Subject: [PATCH] dev: sorts deprecated linters at the end of lists (#4642) --- pkg/commands/help.go | 17 +++++++++++++++-- scripts/website/expand_templates/linters.go | 17 +++++++++++++++++ scripts/website/types/types.go | 4 ++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/pkg/commands/help.go b/pkg/commands/help.go index cb398fe5..094e5d19 100644 --- a/pkg/commands/help.go +++ b/pkg/commands/help.go @@ -2,6 +2,7 @@ package commands import ( "fmt" + "slices" "sort" "strings" @@ -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 { diff --git a/scripts/website/expand_templates/linters.go b/scripts/website/expand_templates/linters.go index ba4ff3d2..1b1e3023 100644 --- a/scripts/website/expand_templates/linters.go +++ b/scripts/website/expand_templates/linters.go @@ -5,6 +5,7 @@ import ( "os" "path/filepath" "reflect" + "slices" "sort" "strings" "unicode" @@ -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|", "|---|---|---|---|---|---|", diff --git a/scripts/website/types/types.go b/scripts/website/types/types.go index 955c6c43..7a5fcc4e 100644 --- a/scripts/website/types/types.go +++ b/scripts/website/types/types.go @@ -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 +}