Skip to content

Commit 9ebd084

Browse files
Stanislav (Stas) Katkovskatkov
authored andcommitted
resolve perf issues highlighted by golangci-lint
1 parent b49caad commit 9ebd084

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

cmd/jsonrepair.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"errors"
45
"fmt"
56
"io"
67

@@ -42,7 +43,7 @@ This tool can fix various JSON issues including:
4243
}
4344

4445
if len(data) == 0 {
45-
return fmt.Errorf("no input provided. Pipe JSON input to this command")
46+
return errors.New("no input provided. Pipe JSON input to this command")
4647
}
4748

4849
result, err := jsonrepair.RepairJSON(string(data))

docs/tui-docs.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,9 @@ Most TUI tools share these common key bindings:
258258
}
259259

260260
func generateModuleFile(sitePath string, module TUIModule) error {
261-
content := fmt.Sprintf(`---
261+
var builder strings.Builder
262+
263+
fmt.Fprintf(&builder, `---
262264
title: %s
263265
parent: TUI
264266
---
@@ -277,23 +279,18 @@ parent: TUI
277279
`, module.Title, module.Title)
278280

279281
if len(module.KeyBindings) > 0 {
280-
content += "| Key | Action |\n|-----|--------|\n"
281-
var builder strings.Builder
282+
builder.WriteString("| Key | Action |\n|-----|--------|\n")
282283
for _, binding := range module.KeyBindings {
283-
builder.WriteString(fmt.Sprintf("| `%s` | %s |\n", binding.Key, binding.Description))
284+
fmt.Fprintf(&builder, "| `%s` | %s |\n", binding.Key, binding.Description)
284285
}
285-
content += builder.String()
286286
} else {
287-
content += "Standard key bindings apply (see main TUI documentation).\n"
287+
builder.WriteString("Standard key bindings apply (see main TUI documentation).\n")
288288
}
289289

290-
content += `
291-
292-
293-
`
290+
builder.WriteString("\n\n")
294291

295292
filename := module.Name + ".md"
296-
return os.WriteFile(filepath.Join(sitePath, filename), []byte(content), 0o644)
293+
return os.WriteFile(filepath.Join(sitePath, filename), []byte(builder.String()), 0o644)
297294
}
298295

299296
func GenerateTUIDocumentation() error {

internal/csv2md/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ func Convert(header string, records [][]string, aligned bool) []string {
3939
// build markdown table
4040
for row_idx, row := range records {
4141
// table content
42-
var sb strings.Builder
43-
sb.WriteString("| ")
42+
var builder strings.Builder
43+
builder.WriteString("| ")
4444
for col_idx, col := range row {
4545
if aligned {
46-
sb.WriteString(fmt.Sprintf("%-*s | ", widths[col_idx], col))
46+
fmt.Fprintf(&builder, "%-*s | ", widths[col_idx], col)
4747
} else {
48-
sb.WriteString(col + " | ")
48+
builder.WriteString(col + " | ")
4949
}
5050
}
51-
result = append(result, sb.String())
51+
result = append(result, builder.String())
5252

5353
// content separator only after first row (header)
5454
if row_idx == 0 {

0 commit comments

Comments
 (0)