Skip to content

docs: add linters description #3945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 11, 2023
38 changes: 35 additions & 3 deletions scripts/expand_website_templates/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"reflect"
"sort"
"strings"
"unicode"
"unicode/utf8"

"gopkg.in/yaml.v3"

Expand Down Expand Up @@ -302,7 +304,20 @@ func getDesc(lc *linter.Config) string {
}
}

return strings.ReplaceAll(desc, "\n", "<br/>")
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", "<br/>")
}

func check(b bool, title string) string {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down