Skip to content

Commit c22180a

Browse files
committed
refactor: ran: modernize -fix ./...
1 parent d5781e2 commit c22180a

File tree

6 files changed

+14
-37
lines changed

6 files changed

+14
-37
lines changed

internal/engine/getent.go

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"bufio"
66
"fmt"
77
"os"
8+
"slices"
89
"strings"
910

1011
"go.pennock.tech/aifr/pkg/protocol"
@@ -194,13 +195,7 @@ func parseColonFile(path string, mapper fieldMapper, key string) ([]protocol.Get
194195
}
195196

196197
if key != "" {
197-
matched := false
198-
for _, k := range keys {
199-
if k == key {
200-
matched = true
201-
break
202-
}
203-
}
198+
matched := slices.Contains(keys, key)
204199
if !matched {
205200
continue
206201
}
@@ -268,13 +263,7 @@ func parseServicesFile(path, key, protoFilter string) ([]protocol.GetentEntry, e
268263

269264
if key != "" && name != key && port != key {
270265
// Also check aliases.
271-
matched := false
272-
for _, a := range parts[2:] {
273-
if a == key {
274-
matched = true
275-
break
276-
}
277-
}
266+
matched := slices.Contains(parts[2:], key)
278267
if !matched {
279268
continue
280269
}
@@ -329,13 +318,7 @@ func parseProtocolsFile(path, key string) ([]protocol.GetentEntry, error) {
329318
}
330319

331320
if key != "" && name != key && number != key {
332-
matched := false
333-
for _, a := range parts[2:] {
334-
if a == key {
335-
matched = true
336-
break
337-
}
338-
}
321+
matched := slices.Contains(parts[2:], key)
339322
if !matched {
340323
continue
341324
}

internal/engine/gitops.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ func computeByteDiff(a, b string) (identical bool, bd *protocol.ByteDiff) {
386386

387387
line := 1
388388
col := 1
389-
for i := 0; i < n; i++ {
389+
for i := range n {
390390
if dataA[i] != dataB[i] {
391391
return false, &protocol.ByteDiff{
392392
Offset: int64(i),

internal/engine/search.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,7 @@ func (e *Engine) searchFile(root, path string, re *regexp.Regexp, params SearchP
186186

187187
// Context lines.
188188
if params.Context > 0 {
189-
startCtx := lineIdx - params.Context
190-
if startCtx < 0 {
191-
startCtx = 0
192-
}
189+
startCtx := max(lineIdx-params.Context, 0)
193190
endCtx := lineIdx + params.Context
194191
if endCtx >= len(allLines) {
195192
endCtx = len(allLines) - 1

internal/engine/search_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package engine
44
import (
55
"os"
66
"path/filepath"
7+
"strings"
78
"testing"
89
"time"
910
)
@@ -81,11 +82,11 @@ func TestSearchWithContext(t *testing.T) {
8182
func TestSearchMaxMatches(t *testing.T) {
8283
dir := t.TempDir()
8384
// Create a file with many matches.
84-
content := ""
85-
for i := 0; i < 100; i++ {
86-
content += "match\n"
85+
var content strings.Builder
86+
for range 100 {
87+
content.WriteString("match\n")
8788
}
88-
mkTestFile(t, dir, "many.txt", content)
89+
mkTestFile(t, dir, "many.txt", content.String())
8990
eng := newTestEngine(t, dir)
9091

9192
resp, err := eng.Search("match", dir, SearchParams{MaxMatches: 5})

internal/engine/sortlimit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func compareVersions(a, b string) int {
9595

9696
n := min(len(segsA), len(segsB))
9797

98-
for i := 0; i < n; i++ {
98+
for i := range n {
9999
sa, sb := segsA[i], segsB[i]
100100
// Try numeric comparison first.
101101
na, errA := strconv.ParseInt(sa, 10, 64)

internal/engine/sysinfo.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net"
77
"os"
88
"runtime"
9+
"slices"
910
"time"
1011

1112
"go.pennock.tech/aifr/pkg/protocol"
@@ -20,12 +21,7 @@ func (p *SysinfoParams) include(section string) bool {
2021
if len(p.Sections) == 0 {
2122
return true
2223
}
23-
for _, s := range p.Sections {
24-
if s == section {
25-
return true
26-
}
27-
}
28-
return false
24+
return slices.Contains(p.Sections, section)
2925
}
3026

3127
// Sysinfo gathers system information for fault diagnosis.

0 commit comments

Comments
 (0)