Skip to content

Commit b4f227d

Browse files
committed
fix lint
1 parent 44612d1 commit b4f227d

5 files changed

Lines changed: 23 additions & 39 deletions

File tree

cmd/loop/main.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,8 @@ func defaultPathText(value string, homeDir func() (string, error)) string {
209209
}
210210

211211
prefix := cleanHome + string(filepath.Separator)
212-
if strings.HasPrefix(cleanValue, prefix) {
213-
return "~" + string(filepath.Separator) +
214-
strings.TrimPrefix(cleanValue, prefix)
212+
if suffix, ok := strings.CutPrefix(cleanValue, prefix); ok {
213+
return "~" + string(filepath.Separator) + suffix
215214
}
216215

217216
return value
@@ -377,7 +376,7 @@ func maybeNormalizeJSON(raw []byte) []byte {
377376
return raw
378377
}
379378

380-
var parsed interface{}
379+
var parsed any
381380
if err := json.Unmarshal(raw, &parsed); err != nil {
382381
return raw
383382
}

cmd/loop/session_fixture_update_test.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ func rewriteTextEvents(events []sessionEvent, kind, recorded, actual string,
205205
}
206206

207207
if normalizedEqual && textEventsMatch(events, kind, replacement) {
208-
209208
return events, changed, nil
210209
}
211210

@@ -221,6 +220,7 @@ func rewriteTextEvents(events []sessionEvent, kind, recorded, actual string,
221220
// stream.
222221
func canonicalTextEvents(events []sessionEvent, kind string, chunks []string,
223222
combined string) ([]sessionEvent, error) {
223+
224224
indices := textEventIndices(events, kind)
225225
replacement := replacementTextChunks(chunks, combined)
226226
if len(indices) != len(replacement) {
@@ -253,6 +253,7 @@ func replaceTextEvents(events []sessionEvent, kind string,
253253
// event stream.
254254
func replaceTextEventsWithCanonical(events []sessionEvent, kind string,
255255
indices []int, replacements []sessionEvent) ([]sessionEvent, error) {
256+
256257
if len(indices) == len(replacements) {
257258
updated := append([]sessionEvent(nil), events...)
258259
for i, idx := range indices {
@@ -458,15 +459,10 @@ func cloneOptionalString(value *string) *string {
458459

459460
// TestUpdateRecordedSessionsEnabled verifies update-mode env parsing.
460461
func TestUpdateRecordedSessionsEnabled(t *testing.T) {
461-
prev, hadPrev := os.LookupEnv(updateRecordedSessionsEnvVar)
462-
if hadPrev {
463-
defer func() {
464-
_ = os.Setenv(updateRecordedSessionsEnvVar, prev)
465-
}()
462+
if current, ok := os.LookupEnv(updateRecordedSessionsEnvVar); ok {
463+
t.Setenv(updateRecordedSessionsEnvVar, current)
466464
} else {
467-
defer func() {
468-
_ = os.Unsetenv(updateRecordedSessionsEnvVar)
469-
}()
465+
t.Setenv(updateRecordedSessionsEnvVar, "")
470466
}
471467

472468
_ = os.Unsetenv(updateRecordedSessionsEnvVar)
@@ -475,12 +471,12 @@ func TestUpdateRecordedSessionsEnabled(t *testing.T) {
475471
require.NoError(t, err)
476472
require.False(t, enabled)
477473

478-
require.NoError(t, os.Setenv(updateRecordedSessionsEnvVar, "true"))
474+
t.Setenv(updateRecordedSessionsEnvVar, "true")
479475
enabled, err = updateRecordedSessionsEnabled()
480476
require.NoError(t, err)
481477
require.True(t, enabled)
482478

483-
require.NoError(t, os.Setenv(updateRecordedSessionsEnvVar, "invalid"))
479+
t.Setenv(updateRecordedSessionsEnvVar, "invalid")
484480
enabled, err = updateRecordedSessionsEnabled()
485481
require.False(t, enabled)
486482
require.EqualError(t, err,

cmd/loop/session_recorder.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (r *sessionRecorder) resolveFilePath() (string, string, error) {
236236
}
237237

238238
// logEvent records a new event with the elapsed timestamp.
239-
func (r *sessionRecorder) logEvent(kind string, payload interface{}) {
239+
func (r *sessionRecorder) logEvent(kind string, payload any) {
240240
data, err := json.Marshal(payload)
241241
if err != nil {
242242
return
@@ -428,7 +428,7 @@ func (r *sessionRecorder) Dial(cmd *cli.Command) (daemonConn, func(), error) {
428428

429429
// UnaryInterceptor captures unary RPCs for session playback.
430430
func (r *sessionRecorder) UnaryInterceptor() grpc.UnaryClientInterceptor {
431-
return func(ctx context.Context, method string, req, reply interface{},
431+
return func(ctx context.Context, method string, req, reply any,
432432
cc *grpc.ClientConn, invoker grpc.UnaryInvoker,
433433
opts ...grpc.CallOption) error {
434434

@@ -477,7 +477,7 @@ type recordingClientStream struct {
477477
}
478478

479479
// SendMsg records the outgoing stream message.
480-
func (s *recordingClientStream) SendMsg(m interface{}) error {
480+
func (s *recordingClientStream) SendMsg(m any) error {
481481
s.recorder.logGRPCMessage(s.method, "send", m, nil)
482482
err := s.ClientStream.SendMsg(m)
483483
if err != nil {
@@ -488,7 +488,7 @@ func (s *recordingClientStream) SendMsg(m interface{}) error {
488488
}
489489

490490
// RecvMsg records the incoming stream message.
491-
func (s *recordingClientStream) RecvMsg(m interface{}) error {
491+
func (s *recordingClientStream) RecvMsg(m any) error {
492492
err := s.ClientStream.RecvMsg(m)
493493
if err != nil {
494494
s.recorder.logGRPCMessage(s.method, "error", nil, err)
@@ -502,7 +502,7 @@ func (s *recordingClientStream) RecvMsg(m interface{}) error {
502502
}
503503

504504
// logGRPCMessage captures gRPC request/response data in the event stream.
505-
func (r *sessionRecorder) logGRPCMessage(method, event string, msg interface{},
505+
func (r *sessionRecorder) logGRPCMessage(method, event string, msg any,
506506
receptionErr error) {
507507

508508
payload := grpcPayload{Method: method, Event: event}

cmd/loop/session_replay_test.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"reflect"
1414
"regexp"
1515
"runtime"
16+
"slices"
1617
"strings"
1718
"sync"
1819
"testing"
@@ -537,13 +538,7 @@ func compareJSONWithContext(method, event string, idx int, actual []byte,
537538

538539
// contains returns true when v is in the slice.
539540
func contains(values []string, v string) bool {
540-
for _, value := range values {
541-
if value == v {
542-
return true
543-
}
544-
}
545-
546-
return false
541+
return slices.Contains(values, v)
547542
}
548543

549544
// TestRecordedSessions replays all recorded sessions and compares output.
@@ -1208,10 +1203,8 @@ func findFlagByName(t *testing.T, flags []cli.Flag, name string) cli.Flag {
12081203
if flag == nil {
12091204
continue
12101205
}
1211-
for _, candidate := range flag.Names() {
1212-
if candidate == name {
1213-
return flag
1214-
}
1206+
if slices.Contains(flag.Names(), name) {
1207+
return flag
12151208
}
12161209
}
12171210
t.Fatalf("flag %q not found", name)

cmd/loop/session_stdio.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,14 @@ func hookOutput(setDest func(*os.File), orig *os.File, forward io.Writer,
4242
setDest(w)
4343

4444
var wg sync.WaitGroup
45-
wg.Add(1)
46-
go func() {
47-
defer wg.Done()
45+
wg.Go(func() {
4846
defer r.Close()
4947

5048
writer := composeWriter(forward, onChunk)
5149
// Restoring the original descriptor closes the pipe from the other
5250
// side, so io.Copy can fail as part of normal teardown.
5351
_, _ = io.Copy(writer, r)
54-
}()
52+
})
5553

5654
return func() error {
5755
setDest(orig)
@@ -86,15 +84,13 @@ func hookStdin(orig *os.File, source io.Reader,
8684
os.Stdin = r
8785

8886
var wg sync.WaitGroup
89-
wg.Add(1)
90-
go func() {
91-
defer wg.Done()
87+
wg.Go(func() {
9288
defer w.Close()
9389

9490
// Closing the pipe during hook restoration can terminate the copy
9591
// loop with an expected error.
9692
_, _ = io.Copy(w, source)
97-
}()
93+
})
9894

9995
return func() error {
10096
os.Stdin = orig

0 commit comments

Comments
 (0)