From b23078107fa09dc341902f763c13ba69577fb338 Mon Sep 17 00:00:00 2001 From: James Lucktaylor Date: Sat, 23 Jan 2021 10:34:56 +0000 Subject: [PATCH] fix(cmd/linters): truncate multiline descriptions For any linters that have a multiline description, displaying such as part of the 'golangci-lint linters' output can be confusing, especially without colourised output on your terminal. fix #1594 --- pkg/commands/help.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/commands/help.go b/pkg/commands/help.go index 16fef33ebc2c..ef276481c718 100644 --- a/pkg/commands/help.go +++ b/pkg/commands/help.go @@ -45,8 +45,16 @@ func printLinterConfigs(lcs []*linter.Config) { if len(lc.AlternativeNames) != 0 { altNamesStr = fmt.Sprintf(" (%s)", strings.Join(lc.AlternativeNames, ", ")) } + + // If the linter description spans multiple lines, truncate everything following the first newline + linterDescription := lc.Linter.Desc() + firstNewline := strings.IndexRune(linterDescription, '\n') + if firstNewline > 0 { + linterDescription = linterDescription[:firstNewline] + } + fmt.Fprintf(logutils.StdOut, "%s%s: %s [fast: %t, auto-fix: %t]\n", color.YellowString(lc.Name()), - altNamesStr, lc.Linter.Desc(), !lc.IsSlowLinter(), lc.CanAutoFix) + altNamesStr, linterDescription, !lc.IsSlowLinter(), lc.CanAutoFix) } }