Skip to content

Commit e955af1

Browse files
alexandearldez
andauthored
dev: format linter descriptions inside help command (#5205)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent 59f05b5 commit e955af1

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

pkg/commands/help.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"slices"
66
"sort"
77
"strings"
8+
"unicode"
9+
"unicode/utf8"
810

911
"github.com/fatih/color"
1012
"github.com/spf13/cobra"
@@ -124,11 +126,21 @@ func printLinters(lcs []*linter.Config) {
124126
})
125127

126128
for _, lc := range lcs {
129+
desc := lc.Linter.Desc()
130+
127131
// If the linter description spans multiple lines, truncate everything following the first newline
128-
linterDescription := lc.Linter.Desc()
129-
firstNewline := strings.IndexRune(linterDescription, '\n')
130-
if firstNewline > 0 {
131-
linterDescription = linterDescription[:firstNewline]
132+
endFirstLine := strings.IndexRune(desc, '\n')
133+
if endFirstLine > 0 {
134+
desc = desc[:endFirstLine]
135+
}
136+
137+
rawDesc := []rune(desc)
138+
139+
r, _ := utf8.DecodeRuneInString(desc)
140+
rawDesc[0] = unicode.ToUpper(r)
141+
142+
if rawDesc[len(rawDesc)-1] != '.' {
143+
rawDesc = append(rawDesc, '.')
132144
}
133145

134146
deprecatedMark := ""
@@ -137,6 +149,6 @@ func printLinters(lcs []*linter.Config) {
137149
}
138150

139151
_, _ = fmt.Fprintf(logutils.StdOut, "%s%s: %s [fast: %t, auto-fix: %t]\n",
140-
color.YellowString(lc.Name()), deprecatedMark, linterDescription, !lc.IsSlowLinter(), lc.CanAutoFix)
152+
color.YellowString(lc.Name()), deprecatedMark, string(rawDesc), !lc.IsSlowLinter(), lc.CanAutoFix)
141153
}
142154
}

0 commit comments

Comments
 (0)