From c7940c7095a979562820fe023ed9ea0094c2099e Mon Sep 17 00:00:00 2001 From: Aldana Longhi Date: Fri, 7 Jul 2023 16:49:07 -0300 Subject: [PATCH 01/10] add description to linters in usages/linters --- scripts/expand_website_templates/main.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/expand_website_templates/main.go b/scripts/expand_website_templates/main.go index f5566a95d316..74f5f21b867d 100644 --- a/scripts/expand_website_templates/main.go +++ b/scripts/expand_website_templates/main.go @@ -468,7 +468,14 @@ func extractExampleSnippets(example []byte) (*SettingSnippets, error) { globalNode.Content = append(globalNode.Content, node, newNode) if node.Value == "linters-settings" { - snippets.LintersSettings, err = getLintersSettingSnippets(node, nextNode) + var lintersDesc = make(map[string]string) + lcs := lintersdb.NewManager(nil, nil).GetAllSupportedLinterConfigs() + + for _, lint := range lcs { + lintersDesc[getName(lint)] = getDesc(lint) + } + + snippets.LintersSettings, err = getLintersSettingSnippets(node, nextNode, lintersDesc) if err != nil { return nil, err } @@ -508,7 +515,7 @@ func extractExampleSnippets(example []byte) (*SettingSnippets, error) { return &snippets, nil } -func getLintersSettingSnippets(node, nextNode *yaml.Node) (string, error) { +func getLintersSettingSnippets(node, nextNode *yaml.Node, lintersDesc map[string]string) (string, error) { builder := &strings.Builder{} for i := 0; i < len(nextNode.Content); i += 2 { @@ -530,6 +537,7 @@ func getLintersSettingSnippets(node, nextNode *yaml.Node) (string, error) { } _, _ = fmt.Fprintf(builder, "### %s\n\n", nextNode.Content[i].Value) + _, _ = fmt.Fprintf(builder, "%s\n\n", lintersDesc[nextNode.Content[i].Value]) _, _ = fmt.Fprintln(builder, "```yaml") encoder := yaml.NewEncoder(builder) From 72e7886f5965609971dcec7a1f57dc43b1d5a410 Mon Sep 17 00:00:00 2001 From: Aldana Longhi Date: Fri, 7 Jul 2023 17:44:34 -0300 Subject: [PATCH 02/10] add function for normalizing linter descriptions to a standard format --- scripts/expand_website_templates/main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/expand_website_templates/main.go b/scripts/expand_website_templates/main.go index 74f5f21b867d..1d2b1f596a47 100644 --- a/scripts/expand_website_templates/main.go +++ b/scripts/expand_website_templates/main.go @@ -302,7 +302,7 @@ func getDesc(lc *linter.Config) string { } } - return strings.ReplaceAll(desc, "\n", "
") + return normalizeDesc(strings.ReplaceAll(desc, "\n", "
")) } func check(b bool, title string) string { @@ -578,3 +578,13 @@ func marshallSnippet(node *yaml.Node) (string, error) { return builder.String(), nil } + +func normalizeDesc(dsc string) string { + dsc = strings.ToUpper(dsc) + fmt.Println(dsc[len(dsc)-2:]) + if dsc[len(dsc)-1:] != "." { + dsc = fmt.Sprintf("%s.", dsc) + } + + return dsc +} From 68365aabd76782c4df981d983c7e4b70098fe3ff Mon Sep 17 00:00:00 2001 From: Aldana Longhi Date: Sun, 9 Jul 2023 17:23:28 -0300 Subject: [PATCH 03/10] refactor logic in normalization function to linter description --- scripts/expand_website_templates/main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/expand_website_templates/main.go b/scripts/expand_website_templates/main.go index 1d2b1f596a47..85366f118ac7 100644 --- a/scripts/expand_website_templates/main.go +++ b/scripts/expand_website_templates/main.go @@ -16,13 +16,13 @@ import ( "reflect" "sort" "strings" - - "gopkg.in/yaml.v3" + "unicode" "github.com/golangci/golangci-lint/internal/renameio" "github.com/golangci/golangci-lint/pkg/config" "github.com/golangci/golangci-lint/pkg/lint/linter" "github.com/golangci/golangci-lint/pkg/lint/lintersdb" + "gopkg.in/yaml.v3" ) const listItemPrefix = "list-item-" @@ -580,8 +580,8 @@ func marshallSnippet(node *yaml.Node) (string, error) { } func normalizeDesc(dsc string) string { - dsc = strings.ToUpper(dsc) - fmt.Println(dsc[len(dsc)-2:]) + runes := []rune(dsc) + runes[0] = unicode.ToUpper([]rune(dsc)[0]) if dsc[len(dsc)-1:] != "." { dsc = fmt.Sprintf("%s.", dsc) } From 291cf5854d733227efb01279d636d62b8ce12207 Mon Sep 17 00:00:00 2001 From: Aldana Longhi Date: Sun, 9 Jul 2023 17:24:24 -0300 Subject: [PATCH 04/10] change name for normalizing function for better understanding --- scripts/expand_website_templates/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/expand_website_templates/main.go b/scripts/expand_website_templates/main.go index 85366f118ac7..c1f1ddd637df 100644 --- a/scripts/expand_website_templates/main.go +++ b/scripts/expand_website_templates/main.go @@ -302,7 +302,7 @@ func getDesc(lc *linter.Config) string { } } - return normalizeDesc(strings.ReplaceAll(desc, "\n", "
")) + return capitalizeAndAddFinalDot(strings.ReplaceAll(desc, "\n", "
")) } func check(b bool, title string) string { @@ -579,7 +579,7 @@ func marshallSnippet(node *yaml.Node) (string, error) { return builder.String(), nil } -func normalizeDesc(dsc string) string { +func capitalizeAndAddFinalDot(dsc string) string { runes := []rune(dsc) runes[0] = unicode.ToUpper([]rune(dsc)[0]) if dsc[len(dsc)-1:] != "." { From 483d0fa5e3c1396c6d1a3915432064b2cebe9019 Mon Sep 17 00:00:00 2001 From: Aldana Longhi Date: Sun, 9 Jul 2023 17:40:50 -0300 Subject: [PATCH 05/10] replace getName function for Name in description mapping --- scripts/expand_website_templates/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/expand_website_templates/main.go b/scripts/expand_website_templates/main.go index c1f1ddd637df..5a9787ac93bb 100644 --- a/scripts/expand_website_templates/main.go +++ b/scripts/expand_website_templates/main.go @@ -472,7 +472,7 @@ func extractExampleSnippets(example []byte) (*SettingSnippets, error) { lcs := lintersdb.NewManager(nil, nil).GetAllSupportedLinterConfigs() for _, lint := range lcs { - lintersDesc[getName(lint)] = getDesc(lint) + lintersDesc[lint.Name()] = getDesc(lint) } snippets.LintersSettings, err = getLintersSettingSnippets(node, nextNode, lintersDesc) From a80b008b1b0293add24ecd10a178345709941a29 Mon Sep 17 00:00:00 2001 From: Aldana Longhi Date: Sun, 9 Jul 2023 17:41:41 -0300 Subject: [PATCH 06/10] add missing variable asignment line in function --- scripts/expand_website_templates/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/expand_website_templates/main.go b/scripts/expand_website_templates/main.go index 5a9787ac93bb..bb367d2ad964 100644 --- a/scripts/expand_website_templates/main.go +++ b/scripts/expand_website_templates/main.go @@ -582,6 +582,7 @@ func marshallSnippet(node *yaml.Node) (string, error) { func capitalizeAndAddFinalDot(dsc string) string { runes := []rune(dsc) runes[0] = unicode.ToUpper([]rune(dsc)[0]) + dsc = string(runes) if dsc[len(dsc)-1:] != "." { dsc = fmt.Sprintf("%s.", dsc) } From dcd876b57e914414a08ec4a172b92d0331538e95 Mon Sep 17 00:00:00 2001 From: Aldana Longhi Date: Mon, 10 Jul 2023 09:33:03 -0300 Subject: [PATCH 07/10] move import to previous location --- scripts/expand_website_templates/main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/expand_website_templates/main.go b/scripts/expand_website_templates/main.go index bb367d2ad964..600902db9acf 100644 --- a/scripts/expand_website_templates/main.go +++ b/scripts/expand_website_templates/main.go @@ -18,11 +18,12 @@ import ( "strings" "unicode" + "gopkg.in/yaml.v3" + "github.com/golangci/golangci-lint/internal/renameio" "github.com/golangci/golangci-lint/pkg/config" "github.com/golangci/golangci-lint/pkg/lint/linter" "github.com/golangci/golangci-lint/pkg/lint/lintersdb" - "gopkg.in/yaml.v3" ) const listItemPrefix = "list-item-" From 8d9bf09eac9d51de47531dec562114aa99fc77d7 Mon Sep 17 00:00:00 2001 From: Aldana Longhi Date: Mon, 10 Jul 2023 09:35:03 -0300 Subject: [PATCH 08/10] resolve comments in PR / refactor in formatting function por linter's description --- scripts/expand_website_templates/main.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/expand_website_templates/main.go b/scripts/expand_website_templates/main.go index 600902db9acf..8ee8c4aa246a 100644 --- a/scripts/expand_website_templates/main.go +++ b/scripts/expand_website_templates/main.go @@ -303,7 +303,7 @@ func getDesc(lc *linter.Config) string { } } - return capitalizeAndAddFinalDot(strings.ReplaceAll(desc, "\n", "
")) + return formatDesc(desc) } func check(b bool, title string) string { @@ -580,13 +580,13 @@ func marshallSnippet(node *yaml.Node) (string, error) { return builder.String(), nil } -func capitalizeAndAddFinalDot(dsc string) string { - runes := []rune(dsc) - runes[0] = unicode.ToUpper([]rune(dsc)[0]) - dsc = string(runes) - if dsc[len(dsc)-1:] != "." { - dsc = fmt.Sprintf("%s.", dsc) +func formatDesc(desc string) string { + runes := []rune(desc) + runes[0] = unicode.ToUpper([]rune(desc)[0]) + + if desc[len(desc)-1:] != "." { + desc = fmt.Sprintf("%s.", desc) } - return dsc + return strings.ReplaceAll(string(runes), "\n", "
") } From f67aef758b9a1d050ddb86f53ccd44da6dfef99f Mon Sep 17 00:00:00 2001 From: Aldana Longhi Date: Mon, 10 Jul 2023 09:42:04 -0300 Subject: [PATCH 09/10] fix logic in function for formatting linter's description --- scripts/expand_website_templates/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/expand_website_templates/main.go b/scripts/expand_website_templates/main.go index 8ee8c4aa246a..61dea7bff23f 100644 --- a/scripts/expand_website_templates/main.go +++ b/scripts/expand_website_templates/main.go @@ -584,8 +584,8 @@ func formatDesc(desc string) string { runes := []rune(desc) runes[0] = unicode.ToUpper([]rune(desc)[0]) - if desc[len(desc)-1:] != "." { - desc = fmt.Sprintf("%s.", desc) + if runes[len(runes)-1] != '.' { + runes = append(runes, '.') } return strings.ReplaceAll(string(runes), "\n", "
") From d5fc9a4a3e3cf504f2ab700fd70a63bd1ba1df26 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Tue, 11 Jul 2023 10:49:38 +0200 Subject: [PATCH 10/10] review: minor changes --- scripts/expand_website_templates/main.go | 52 +++++++++++++++--------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/scripts/expand_website_templates/main.go b/scripts/expand_website_templates/main.go index 61dea7bff23f..0e38900f23b8 100644 --- a/scripts/expand_website_templates/main.go +++ b/scripts/expand_website_templates/main.go @@ -17,6 +17,7 @@ import ( "sort" "strings" "unicode" + "unicode/utf8" "gopkg.in/yaml.v3" @@ -306,6 +307,19 @@ func getDesc(lc *linter.Config) string { return formatDesc(desc) } +func formatDesc(desc string) string { + runes := []rune(desc) + + r, _ := utf8.DecodeRuneInString(desc) + runes[0] = unicode.ToUpper(r) + + if runes[len(runes)-1] != '.' { + runes = append(runes, '.') + } + + return strings.ReplaceAll(string(runes), "\n", "
") +} + func check(b bool, title string) string { if b { return span(title, "✔") @@ -343,6 +357,10 @@ func getThanksList() string { addedAuthors := map[string]*authorDetails{} for _, lc := range lintersdb.NewManager(nil, nil).GetAllSupportedLinterConfigs() { + if lc.Internal { + continue + } + if lc.OriginalURL == "" { continue } @@ -469,14 +487,7 @@ func extractExampleSnippets(example []byte) (*SettingSnippets, error) { globalNode.Content = append(globalNode.Content, node, newNode) if node.Value == "linters-settings" { - var lintersDesc = make(map[string]string) - lcs := lintersdb.NewManager(nil, nil).GetAllSupportedLinterConfigs() - - for _, lint := range lcs { - lintersDesc[lint.Name()] = getDesc(lint) - } - - snippets.LintersSettings, err = getLintersSettingSnippets(node, nextNode, lintersDesc) + snippets.LintersSettings, err = getLintersSettingSections(node, nextNode) if err != nil { return nil, err } @@ -516,7 +527,19 @@ func extractExampleSnippets(example []byte) (*SettingSnippets, error) { return &snippets, nil } -func getLintersSettingSnippets(node, nextNode *yaml.Node, lintersDesc map[string]string) (string, error) { +func getLintersSettingSections(node, nextNode *yaml.Node) (string, error) { + lcs := lintersdb.NewManager(nil, nil).GetAllSupportedLinterConfigs() + + var lintersDesc = make(map[string]string) + for _, lc := range lcs { + if lc.Internal { + continue + } + + // it's important to use lc.Name() nor name because name can be alias + lintersDesc[lc.Name()] = getDesc(lc) + } + builder := &strings.Builder{} for i := 0; i < len(nextNode.Content); i += 2 { @@ -579,14 +602,3 @@ func marshallSnippet(node *yaml.Node) (string, error) { return builder.String(), nil } - -func formatDesc(desc string) string { - runes := []rune(desc) - runes[0] = unicode.ToUpper([]rune(desc)[0]) - - if runes[len(runes)-1] != '.' { - runes = append(runes, '.') - } - - return strings.ReplaceAll(string(runes), "\n", "
") -}