From d58f1401710f56d06e2a54e460f160f72b8499d2 Mon Sep 17 00:00:00 2001 From: AlduLonghi <60699220+AlduLonghi@users.noreply.github.com> Date: Tue, 11 Jul 2023 10:46:37 -0300 Subject: [PATCH] docs: add linters description (#3945) Co-authored-by: Fernandez Ludovic --- scripts/expand_website_templates/main.go | 38 ++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/scripts/expand_website_templates/main.go b/scripts/expand_website_templates/main.go index f5566a95..0e38900f 100644 --- a/scripts/expand_website_templates/main.go +++ b/scripts/expand_website_templates/main.go @@ -16,6 +16,8 @@ import ( "reflect" "sort" "strings" + "unicode" + "unicode/utf8" "gopkg.in/yaml.v3" @@ -302,7 +304,20 @@ func getDesc(lc *linter.Config) string { } } - return strings.ReplaceAll(desc, "\n", "
") + 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 { @@ -342,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 } @@ -468,7 +487,7 @@ func extractExampleSnippets(example []byte) (*SettingSnippets, error) { globalNode.Content = append(globalNode.Content, node, newNode) if node.Value == "linters-settings" { - snippets.LintersSettings, err = getLintersSettingSnippets(node, nextNode) + snippets.LintersSettings, err = getLintersSettingSections(node, nextNode) if err != nil { return nil, err } @@ -508,7 +527,19 @@ func extractExampleSnippets(example []byte) (*SettingSnippets, error) { return &snippets, nil } -func getLintersSettingSnippets(node, nextNode *yaml.Node) (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 { @@ -530,6 +561,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)