Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/commands/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ func printLinters(lcs []*linter.Config) {
}

func formatDescription(desc string) string {
desc = strings.TrimSpace(desc)

if desc == "" {
return desc
}

// If the linter description spans multiple lines, truncate everything following the first newline
endFirstLine := strings.IndexRune(desc, '\n')
if endFirstLine > 0 {
Expand Down
51 changes: 51 additions & 0 deletions pkg/commands/help_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package commands

import (
"testing"

"github.com/stretchr/testify/assert"
)

func Test_formatDescription(t *testing.T) {
testCases := []struct {
desc string
doc string
expected string
}{
{
desc: "empty description",
doc: "",
expected: "",
},
{
desc: "simple description",
doc: "this is a test",
expected: "This is a test.",
},
{
desc: "formatted description",
doc: "This is a test.",
expected: "This is a test.",
},
{
desc: "multiline description",
doc: "this is a test\nanother line\n",
expected: "This is a test.",
},
{
desc: "leading newline",
doc: "\nThis is a test.",
expected: "This is a test.",
},
}

for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

v := formatDescription(test.doc)

assert.Equal(t, test.expected, v)
})
}
}
Loading