Skip to content

Commit 841cb1a

Browse files
committed
review: replace fmt.Fprintln by a template
1 parent 9d3561b commit 841cb1a

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

Diff for: scripts/website/expand_templates/exclusions.go

+25-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@ package main
22

33
import (
44
"bytes"
5-
"fmt"
65
"path/filepath"
76
"strings"
7+
"text/template"
88

99
"github.com/golangci/golangci-lint/scripts/website/types"
1010
)
1111

12+
const exclusionTmpl = `{{ $tick := "` + "`" + `" }}
13+
### {{ .ID }}
14+
15+
- linter: {{ $tick }}{{ .Linter }}{{ $tick }}
16+
- pattern: {{ $tick }}{{ .Pattern }}{{ $tick }}
17+
- why: {{ .Why }}
18+
`
19+
1220
func getDefaultExclusions() (string, error) {
1321
defaultExcludePatterns, err := readJSONFile[[]types.ExcludePattern](filepath.Join("assets", "default-exclusions.json"))
1422
if err != nil {
@@ -17,13 +25,23 @@ func getDefaultExclusions() (string, error) {
1725

1826
bufferString := bytes.NewBufferString("")
1927

28+
tmpl, err := template.New("exclusions").Parse(exclusionTmpl)
29+
if err != nil {
30+
return "", err
31+
}
32+
2033
for _, pattern := range defaultExcludePatterns {
21-
_, _ = fmt.Fprintln(bufferString)
22-
_, _ = fmt.Fprintf(bufferString, "### %s\n", pattern.ID)
23-
_, _ = fmt.Fprintln(bufferString)
24-
_, _ = fmt.Fprintf(bufferString, "- linter: `%s`\n", pattern.Linter)
25-
_, _ = fmt.Fprintf(bufferString, "- pattern: `%s`\n", strings.ReplaceAll(pattern.Pattern, "`", "`"))
26-
_, _ = fmt.Fprintf(bufferString, "- why: %s\n", pattern.Why)
34+
data := map[string]any{
35+
"ID": pattern.ID,
36+
"Linter": pattern.Linter,
37+
"Pattern": strings.ReplaceAll(pattern.Pattern, "`", "`"),
38+
"Why": pattern.Why,
39+
}
40+
41+
err := tmpl.Execute(bufferString, data)
42+
if err != nil {
43+
return "", err
44+
}
2745
}
2846

2947
return bufferString.String(), nil

0 commit comments

Comments
 (0)