File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -210,6 +210,12 @@ func printLinters(lcs []*linter.Config) {
210210}
211211
212212func formatDescription (desc string ) string {
213+ desc = strings .TrimSpace (desc )
214+
215+ if desc == "" {
216+ return desc
217+ }
218+
213219 // If the linter description spans multiple lines, truncate everything following the first newline
214220 endFirstLine := strings .IndexRune (desc , '\n' )
215221 if endFirstLine > 0 {
Original file line number Diff line number Diff line change 1+ package commands
2+
3+ import (
4+ "testing"
5+
6+ "github.com/stretchr/testify/assert"
7+ )
8+
9+ func Test_formatDescription (t * testing.T ) {
10+ testCases := []struct {
11+ desc string
12+ doc string
13+ expected string
14+ }{
15+ {
16+ desc : "empty description" ,
17+ doc : "" ,
18+ expected : "" ,
19+ },
20+ {
21+ desc : "simple description" ,
22+ doc : "this is a test" ,
23+ expected : "This is a test." ,
24+ },
25+ {
26+ desc : "formatted description" ,
27+ doc : "This is a test." ,
28+ expected : "This is a test." ,
29+ },
30+ {
31+ desc : "multiline description" ,
32+ doc : "this is a test\n another line\n " ,
33+ expected : "This is a test." ,
34+ },
35+ {
36+ desc : "leading newline" ,
37+ doc : "\n This is a test." ,
38+ expected : "This is a test." ,
39+ },
40+ }
41+
42+ for _ , test := range testCases {
43+ t .Run (test .desc , func (t * testing.T ) {
44+ t .Parallel ()
45+
46+ v := formatDescription (test .doc )
47+
48+ assert .Equal (t , test .expected , v )
49+ })
50+ }
51+ }
You can’t perform that action at this time.
0 commit comments