Skip to content

Commit d58f140

Browse files
AlduLonghildez
andauthored
docs: add linters description (#3945)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent c59e60a commit d58f140

File tree

1 file changed

+35
-3
lines changed
  • scripts/expand_website_templates

1 file changed

+35
-3
lines changed

scripts/expand_website_templates/main.go

+35-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import (
1616
"reflect"
1717
"sort"
1818
"strings"
19+
"unicode"
20+
"unicode/utf8"
1921

2022
"gopkg.in/yaml.v3"
2123

@@ -302,7 +304,20 @@ func getDesc(lc *linter.Config) string {
302304
}
303305
}
304306

305-
return strings.ReplaceAll(desc, "\n", "<br/>")
307+
return formatDesc(desc)
308+
}
309+
310+
func formatDesc(desc string) string {
311+
runes := []rune(desc)
312+
313+
r, _ := utf8.DecodeRuneInString(desc)
314+
runes[0] = unicode.ToUpper(r)
315+
316+
if runes[len(runes)-1] != '.' {
317+
runes = append(runes, '.')
318+
}
319+
320+
return strings.ReplaceAll(string(runes), "\n", "<br/>")
306321
}
307322

308323
func check(b bool, title string) string {
@@ -342,6 +357,10 @@ func getThanksList() string {
342357
addedAuthors := map[string]*authorDetails{}
343358

344359
for _, lc := range lintersdb.NewManager(nil, nil).GetAllSupportedLinterConfigs() {
360+
if lc.Internal {
361+
continue
362+
}
363+
345364
if lc.OriginalURL == "" {
346365
continue
347366
}
@@ -468,7 +487,7 @@ func extractExampleSnippets(example []byte) (*SettingSnippets, error) {
468487
globalNode.Content = append(globalNode.Content, node, newNode)
469488

470489
if node.Value == "linters-settings" {
471-
snippets.LintersSettings, err = getLintersSettingSnippets(node, nextNode)
490+
snippets.LintersSettings, err = getLintersSettingSections(node, nextNode)
472491
if err != nil {
473492
return nil, err
474493
}
@@ -508,7 +527,19 @@ func extractExampleSnippets(example []byte) (*SettingSnippets, error) {
508527
return &snippets, nil
509528
}
510529

511-
func getLintersSettingSnippets(node, nextNode *yaml.Node) (string, error) {
530+
func getLintersSettingSections(node, nextNode *yaml.Node) (string, error) {
531+
lcs := lintersdb.NewManager(nil, nil).GetAllSupportedLinterConfigs()
532+
533+
var lintersDesc = make(map[string]string)
534+
for _, lc := range lcs {
535+
if lc.Internal {
536+
continue
537+
}
538+
539+
// it's important to use lc.Name() nor name because name can be alias
540+
lintersDesc[lc.Name()] = getDesc(lc)
541+
}
542+
512543
builder := &strings.Builder{}
513544

514545
for i := 0; i < len(nextNode.Content); i += 2 {
@@ -530,6 +561,7 @@ func getLintersSettingSnippets(node, nextNode *yaml.Node) (string, error) {
530561
}
531562

532563
_, _ = fmt.Fprintf(builder, "### %s\n\n", nextNode.Content[i].Value)
564+
_, _ = fmt.Fprintf(builder, "%s\n\n", lintersDesc[nextNode.Content[i].Value])
533565
_, _ = fmt.Fprintln(builder, "```yaml")
534566

535567
encoder := yaml.NewEncoder(builder)

0 commit comments

Comments
 (0)