Skip to content

Commit f5130df

Browse files
committed
chore: apply go fix cleanups
1 parent b35c65e commit f5130df

3 files changed

Lines changed: 13 additions & 25 deletions

File tree

internal/config/config.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"embed"
66
"fmt"
7+
"maps"
78
"os"
89
"os/exec"
910
"path/filepath"
@@ -26,9 +27,9 @@ type Config struct {
2627

2728
// FilterConfig holds diff filtering configuration.
2829
type FilterConfig struct {
29-
MaxFileLines int `toml:"max_file_lines"` // Max lines per file (0 = use default)
30-
DefaultExcludePatterns []string `toml:"default_exclude_patterns"` // Override built-in defaults
31-
ExcludePatterns []string `toml:"exclude_patterns"` // Additional patterns to exclude
30+
MaxFileLines int `toml:"max_file_lines"` // Max lines per file (0 = use default)
31+
DefaultExcludePatterns []string `toml:"default_exclude_patterns"` // Override built-in defaults
32+
ExcludePatterns []string `toml:"exclude_patterns"` // Additional patterns to exclude
3233
}
3334

3435
// rawConfig is the TOML structure used to detect mutual exclusivity in a single layer.
@@ -134,9 +135,7 @@ func Load() (Config, error) {
134135
if cfg.Engines == nil {
135136
cfg.Engines = map[string]EngineConfig{}
136137
}
137-
for name, ec := range repoCfg.Engines {
138-
cfg.Engines[name] = ec
139-
}
138+
maps.Copy(cfg.Engines, repoCfg.Engines)
140139
}
141140
// Merge filter config from repo
142141
if repoCfg.Filter.MaxFileLines != 0 {
@@ -196,9 +195,7 @@ func loadConfigLayer(data []byte, cfg *Config, source string) error {
196195
if cfg.Engines == nil {
197196
cfg.Engines = map[string]EngineConfig{}
198197
}
199-
for name, ec := range raw.Engines {
200-
cfg.Engines[name] = ec
201-
}
198+
maps.Copy(cfg.Engines, raw.Engines)
202199
}
203200
// Merge filter config
204201
if raw.Filter.MaxFileLines != 0 {

internal/git/filter.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package git
33
import (
44
"fmt"
55
"path/filepath"
6+
"slices"
67
"sort"
78
"strings"
89
)
@@ -103,7 +104,7 @@ func splitDiffByFile(diff string) map[string]string {
103104
var currentContent strings.Builder
104105
var inFile bool
105106

106-
for i := 0; i < len(lines); i++ {
107+
for i := range lines {
107108
line := lines[i]
108109

109110
// Detect start of a new file diff
@@ -221,12 +222,7 @@ func truncateFileDiff(content string, maxLines int, fileName string) (bool, stri
221222

222223
// containsFile checks if filePath is in the given list of exact paths.
223224
func containsFile(filePath string, files []string) bool {
224-
for _, f := range files {
225-
if f == filePath {
226-
return true
227-
}
228-
}
229-
return false
225+
return slices.Contains(files, filePath)
230226
}
231227

232228
// matchesAnyPattern checks if the file path matches any of the glob patterns.

internal/git/filter_test.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package git
22

33
import (
4+
"slices"
45
"strings"
56
"testing"
67
)
@@ -53,7 +54,7 @@ index abc123..def456 100644
5354
+++ b/large.go
5455
@@ -1,100 +1,110 @@
5556
`)
56-
for i := 0; i < 50; i++ {
57+
for range 50 {
5758
sb.WriteString("+new line\n")
5859
}
5960
diff := sb.String()
@@ -246,7 +247,7 @@ index abc123..def456 100644
246247
+++ b/large.go
247248
@@ -1,100 +1,150 @@
248249
`)
249-
for i := 0; i < 100; i++ {
250+
for range 100 {
250251
sb.WriteString("+new line\n")
251252
}
252253
diff := sb.String()
@@ -270,13 +271,7 @@ func TestDefaultExcludePatterns(t *testing.T) {
270271
"**/go.sum",
271272
}
272273
for _, exp := range expected {
273-
found := false
274-
for _, p := range patterns {
275-
if p == exp {
276-
found = true
277-
break
278-
}
279-
}
274+
found := slices.Contains(patterns, exp)
280275
if !found {
281276
t.Errorf("expected pattern %q in defaults", exp)
282277
}

0 commit comments

Comments
 (0)