From 4b090e17cf238ae6a5669d61a0d4cb88a4761b7d Mon Sep 17 00:00:00 2001 From: Oleksandr Redko Date: Sun, 8 Dec 2024 22:59:03 +0200 Subject: [PATCH 1/2] dev: capitalize the first word of the linter description --- go.mod | 2 +- pkg/commands/help.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 12e0b28e5ebd..73978131507a 100644 --- a/go.mod +++ b/go.mod @@ -131,6 +131,7 @@ require ( golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 golang.org/x/mod v0.22.0 golang.org/x/sys v0.28.0 + golang.org/x/text v0.20.0 golang.org/x/tools v0.28.0 gopkg.in/yaml.v3 v3.0.1 honnef.co/go/tools v0.5.1 @@ -199,7 +200,6 @@ require ( go.uber.org/zap v1.24.0 // indirect golang.org/x/exp/typeparams v0.0.0-20241108190413-2d47ceb2692f // indirect golang.org/x/sync v0.10.0 // indirect - golang.org/x/text v0.20.0 // indirect google.golang.org/protobuf v1.34.2 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/pkg/commands/help.go b/pkg/commands/help.go index 094e5d190548..5531273ecf31 100644 --- a/pkg/commands/help.go +++ b/pkg/commands/help.go @@ -8,6 +8,8 @@ import ( "github.com/fatih/color" "github.com/spf13/cobra" + "golang.org/x/text/cases" + "golang.org/x/text/language" "github.com/golangci/golangci-lint/pkg/config" "github.com/golangci/golangci-lint/pkg/lint/linter" @@ -131,6 +133,11 @@ func printLinters(lcs []*linter.Config) { linterDescription = linterDescription[:firstNewline] } + // Capitalize the first word of the linter description + if firstWord, remaining, ok := strings.Cut(linterDescription, " "); ok { + linterDescription = cases.Title(language.Und, cases.NoLower).String(firstWord) + " " + remaining + } + deprecatedMark := "" if lc.IsDeprecated() { deprecatedMark = " [" + color.RedString("deprecated") + "]" From e56b9667311976beee9cd41ef2e6994ed20aea29 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 8 Dec 2024 22:48:07 +0100 Subject: [PATCH 2/2] review: be consistent with the code of the documentation --- go.mod | 2 +- pkg/commands/help.go | 25 +++++++++++++++---------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 73978131507a..12e0b28e5ebd 100644 --- a/go.mod +++ b/go.mod @@ -131,7 +131,6 @@ require ( golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 golang.org/x/mod v0.22.0 golang.org/x/sys v0.28.0 - golang.org/x/text v0.20.0 golang.org/x/tools v0.28.0 gopkg.in/yaml.v3 v3.0.1 honnef.co/go/tools v0.5.1 @@ -200,6 +199,7 @@ require ( go.uber.org/zap v1.24.0 // indirect golang.org/x/exp/typeparams v0.0.0-20241108190413-2d47ceb2692f // indirect golang.org/x/sync v0.10.0 // indirect + golang.org/x/text v0.20.0 // indirect google.golang.org/protobuf v1.34.2 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/pkg/commands/help.go b/pkg/commands/help.go index 5531273ecf31..c86b2068d6f9 100644 --- a/pkg/commands/help.go +++ b/pkg/commands/help.go @@ -5,11 +5,11 @@ import ( "slices" "sort" "strings" + "unicode" + "unicode/utf8" "github.com/fatih/color" "github.com/spf13/cobra" - "golang.org/x/text/cases" - "golang.org/x/text/language" "github.com/golangci/golangci-lint/pkg/config" "github.com/golangci/golangci-lint/pkg/lint/linter" @@ -126,16 +126,21 @@ func printLinters(lcs []*linter.Config) { }) for _, lc := range lcs { + desc := lc.Linter.Desc() + // 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] + endFirstLine := strings.IndexRune(desc, '\n') + if endFirstLine > 0 { + desc = desc[:endFirstLine] } - // Capitalize the first word of the linter description - if firstWord, remaining, ok := strings.Cut(linterDescription, " "); ok { - linterDescription = cases.Title(language.Und, cases.NoLower).String(firstWord) + " " + remaining + rawDesc := []rune(desc) + + r, _ := utf8.DecodeRuneInString(desc) + rawDesc[0] = unicode.ToUpper(r) + + if rawDesc[len(rawDesc)-1] != '.' { + rawDesc = append(rawDesc, '.') } deprecatedMark := "" @@ -144,6 +149,6 @@ func printLinters(lcs []*linter.Config) { } _, _ = fmt.Fprintf(logutils.StdOut, "%s%s: %s [fast: %t, auto-fix: %t]\n", - color.YellowString(lc.Name()), deprecatedMark, linterDescription, !lc.IsSlowLinter(), lc.CanAutoFix) + color.YellowString(lc.Name()), deprecatedMark, string(rawDesc), !lc.IsSlowLinter(), lc.CanAutoFix) } }