From: Anderson A. Giacomolli Date: Mon, 9 Nov 2026 20:54:59 +0000 (-0300) Subject: Check Go names and declarations with revive X-Git-Url: http://git.giacomolli.uk/onechat/commitdiff_plain/087d725b5ab41ad34ffd24938482d45a8b99a080?ds=inline Check Go names and declarations with revive The lint check applies revive to Go declarations and common style rules. Unused callback and interface parameters have blank names, and the command has a package comment for its entry points. --- diff --git a/.golangci.yml b/.golangci.yml index 1a7a596..58a78b4 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,3 +6,4 @@ linters: - errorlint - gocritic - testifylint + - revive diff --git a/build_run_test.go b/build_run_test.go index 64d0d86..aef8922 100644 --- a/build_run_test.go +++ b/build_run_test.go @@ -114,7 +114,7 @@ func TestBuildRunWaitsOnlyBeforeUserMessages(t *testing.T) { var mutex sync.Mutex running, most := 0, 0 server := newModelFake(t) - server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + server.reply = func(w http.ResponseWriter, _ ModelFakeCall) { mutex.Lock() running++ most = max(most, running) diff --git a/compactor_test.go b/compactor_test.go index 8bdf45c..f4c51f4 100644 --- a/compactor_test.go +++ b/compactor_test.go @@ -209,7 +209,7 @@ func TestCompactorFailsWithoutALine(t *testing.T) { }{ { name: "failed call", - reply: func(w http.ResponseWriter, call ModelFakeCall) { + reply: func(w http.ResponseWriter, _ ModelFakeCall) { w.WriteHeader(http.StatusInternalServerError) _, _ = io.WriteString(w, "down") }, @@ -217,7 +217,7 @@ func TestCompactorFailsWithoutALine(t *testing.T) { }, { name: "tool call and no text", - reply: func(w http.ResponseWriter, call ModelFakeCall) { + reply: func(w http.ResponseWriter, _ ModelFakeCall) { modelWriteEvents(w, modelCompletedEvent([]any{map[string]any{"type": "function_call", "name": "zoom", "arguments": "{}"}}, 100, 0, 5)) }, want: "no line", diff --git a/daemon_test.go b/daemon_test.go index 9f45792..6a8cd3e 100644 --- a/daemon_test.go +++ b/daemon_test.go @@ -50,7 +50,7 @@ func TestStopInterruptsTheTurn(t *testing.T) { close(release) }) - server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + server.reply = func(_ http.ResponseWriter, _ ModelFakeCall) { close(arrived) <-release } diff --git a/main.go b/main.go index f4f09c4..ac4afe4 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,4 @@ +// Command onechat runs the agent daemon and its terminal client. package main import ( diff --git a/model_fake_helper_test.go b/model_fake_helper_test.go index e3fb4c6..08c4732 100644 --- a/model_fake_helper_test.go +++ b/model_fake_helper_test.go @@ -81,7 +81,7 @@ func newModelFake(t *testing.T) *ModelFake { t.Helper() f := &ModelFake{ - reply: func(w http.ResponseWriter, call ModelFakeCall) { + reply: func(w http.ResponseWriter, _ ModelFakeCall) { modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("a line")}, 100, 0, 5)) }, } diff --git a/model_test.go b/model_test.go index 11a7d00..e932107 100644 --- a/model_test.go +++ b/model_test.go @@ -104,7 +104,7 @@ func TestClientSendsTheSessionHeaderToChatGPT(t *testing.T) { func TestClientReadsTheStream(t *testing.T) { server := newModelFake(t) - server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + server.reply = func(w http.ResponseWriter, _ ModelFakeCall) { modelWriteEvents(w, map[string]any{"type": "response.created", "response": map[string]any{}}, map[string]any{"type": "response.output_item.done", "item": map[string]any{"type": "reasoning", "encrypted_content": "opaque"}}, @@ -129,7 +129,7 @@ func TestClientReadsTheStream(t *testing.T) { func TestClientTakesTheOutputOfTheCompletedResponse(t *testing.T) { server := newModelFake(t) - server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + server.reply = func(w http.ResponseWriter, _ ModelFakeCall) { modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("only here")}, 10, 0, 2)) } @@ -255,7 +255,7 @@ func TestClientFailsWhenTheResponseFails(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { server := newModelFake(t) - server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + server.reply = func(w http.ResponseWriter, _ ModelFakeCall) { modelWriteEvents(w, tc.events...) } diff --git a/subagent_run_test.go b/subagent_run_test.go index a39d81c..0341ba6 100644 --- a/subagent_run_test.go +++ b/subagent_run_test.go @@ -344,7 +344,7 @@ func TestTellToAFinishedSubagentGoesOnFromItsLog(t *testing.T) { func TestStopEndsASubagentAndItsCommand(t *testing.T) { server := newModelFake(t) - server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + server.reply = func(w http.ResponseWriter, _ ModelFakeCall) { modelWriteEvents(w, modelCompletedEvent([]any{modelFunctionCallItem("fc_1", "call_1", "shell", `{"command":"touch started && sleep 30"}`)}, 100, 0, 5)) } @@ -396,7 +396,7 @@ func TestCloseEndsTheSubagentsWithNoReport(t *testing.T) { close(release) }) - server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + server.reply = func(_ http.ResponseWriter, _ ModelFakeCall) { close(arrived) <-release } diff --git a/telegram_api_test.go b/telegram_api_test.go index 9b66aa4..43e952e 100644 --- a/telegram_api_test.go +++ b/telegram_api_test.go @@ -220,7 +220,7 @@ func TestBotErrorsDoNotHoldTheToken(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { tc.reply(w) })) t.Cleanup(server.Close) diff --git a/telegram_test.go b/telegram_test.go index 5ced143..e360045 100644 --- a/telegram_test.go +++ b/telegram_test.go @@ -16,7 +16,7 @@ import ( func TestOwnerTalksToTheAgentThroughTelegram(t *testing.T) { server := newModelFake(t) - server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + server.reply = func(w http.ResponseWriter, _ ModelFakeCall) { modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("Hello from the agent.")}, 100, 0, 5)) } @@ -100,7 +100,7 @@ func TestStopFromTelegramInterruptsTheTurn(t *testing.T) { close(release) }) - server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + server.reply = func(_ http.ResponseWriter, _ ModelFakeCall) { close(arrived) <-release } @@ -200,7 +200,7 @@ func TestBotSkipsTheWorkOfWhatsAppAndTheSchedules(t *testing.T) { func TestBotStartsAtTheStoredOffset(t *testing.T) { server := newModelFake(t) - server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + server.reply = func(w http.ResponseWriter, _ ModelFakeCall) { modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("ok")}, 100, 0, 5)) } @@ -234,7 +234,7 @@ func TestBotStartsAtTheStoredOffset(t *testing.T) { func TestBotTriesAgainAfterFailures(t *testing.T) { server := newModelFake(t) - server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + server.reply = func(w http.ResponseWriter, _ ModelFakeCall) { modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("ok")}, 100, 0, 5)) } @@ -301,7 +301,7 @@ func TestDeliverTriesAgainAfterATimeout(t *testing.T) { func TestRepliesGoAsRichMessages(t *testing.T) { reply := "**Done.** The table:\n\n| Name | Size |\n|:-----|-----:|\n| `a.go` | 10 |\n\n- one\n- two\n\n```go\nx := 1\n```" server := newModelFake(t) - server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + server.reply = func(w http.ResponseWriter, _ ModelFakeCall) { modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem(reply)}, 100, 0, 5)) } @@ -615,7 +615,7 @@ func TestBotLogsNoTokenWhenTheNetworkFails(t *testing.T) { func TestBotLogsAnOutageOnlyAtItsStartAndEnd(t *testing.T) { server := newModelFake(t) - server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + server.reply = func(w http.ResponseWriter, _ ModelFakeCall) { modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("ok")}, 100, 0, 5)) } diff --git a/turn_test.go b/turn_test.go index 2763965..5d93e08 100644 --- a/turn_test.go +++ b/turn_test.go @@ -208,7 +208,7 @@ func TestInterruptEndsTheTurn(t *testing.T) { func TestFailedCallEndsTheTurnWithoutARetry(t *testing.T) { server := newModelFake(t) - server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + server.reply = func(w http.ResponseWriter, _ ModelFakeCall) { http.Error(w, "busy", http.StatusServiceUnavailable) } diff --git a/view_test.go b/view_test.go index 56abdd6..f3d4e2a 100644 --- a/view_test.go +++ b/view_test.go @@ -144,7 +144,7 @@ func TestRestoreViewRejectsAGap(t *testing.T) { // ViewBuiltTree is a tree with each node built, with 1 byte of text. type ViewBuiltTree struct{} -func (ViewBuiltTree) Built(level, index int) (bool, error) { +func (v ViewBuiltTree) Built(_, _ int) (bool, error) { return true, nil } diff --git a/whatsapp_fake_helper_test.go b/whatsapp_fake_helper_test.go index 7aa558b..8e1da13 100644 --- a/whatsapp_fake_helper_test.go +++ b/whatsapp_fake_helper_test.go @@ -132,7 +132,7 @@ func (f *WhatsAppFake) Disconnect() { } // GetQRChannel gives a new channel of pairing items to the test. -func (f *WhatsAppFake) GetQRChannel(ctx context.Context) (<-chan whatsmeow.QRChannelItem, error) { +func (f *WhatsAppFake) GetQRChannel(_ context.Context) (<-chan whatsmeow.QRChannelItem, error) { items := make(chan whatsmeow.QRChannelItem, 8) f.pairings <- items @@ -140,7 +140,7 @@ func (f *WhatsAppFake) GetQRChannel(ctx context.Context) (<-chan whatsmeow.QRCha } // PairPhone keeps phone and returns whatsappTestCode. -func (f *WhatsAppFake) PairPhone(ctx context.Context, phone string, showPushNotification bool, clientType whatsmeow.PairClientType, clientDisplayName string) (string, error) { +func (f *WhatsAppFake) PairPhone(_ context.Context, phone string, _ bool, _ whatsmeow.PairClientType, _ string) (string, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -150,7 +150,7 @@ func (f *WhatsAppFake) PairPhone(ctx context.Context, phone string, showPushNoti } // Logout counts the logouts and returns logoutErr. -func (f *WhatsAppFake) Logout(ctx context.Context) error { +func (f *WhatsAppFake) Logout(_ context.Context) error { f.mutex.Lock() defer f.mutex.Unlock() @@ -160,7 +160,7 @@ func (f *WhatsAppFake) Logout(ctx context.Context) error { } // GetJoinedGroups returns groups. -func (f *WhatsAppFake) GetJoinedGroups(ctx context.Context) ([]*types.GroupInfo, error) { +func (f *WhatsAppFake) GetJoinedGroups(_ context.Context) ([]*types.GroupInfo, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -176,7 +176,7 @@ func (f *WhatsAppFake) GenerateMessageID() types.MessageID { } // SendMessage keeps the send and returns sendErr. -func (f *WhatsAppFake) SendMessage(ctx context.Context, to types.JID, message *waE2E.Message, extra ...whatsmeow.SendRequestExtra) (whatsmeow.SendResponse, error) { +func (f *WhatsAppFake) SendMessage(_ context.Context, to types.JID, message *waE2E.Message, extra ...whatsmeow.SendRequestExtra) (whatsmeow.SendResponse, error) { f.mutex.Lock() defer f.mutex.Unlock() @@ -229,7 +229,7 @@ func (f *WhatsAppFake) Emit(event any) bool { } // newClient keeps handle and returns the fake as the client of device. -func (f *WhatsAppFake) newClient(device *store.Device, handle func(event any) bool) WhatsAppClient { +func (f *WhatsAppFake) newClient(_ *store.Device, handle func(event any) bool) WhatsAppClient { f.mutex.Lock() defer f.mutex.Unlock() diff --git a/whatsapp_inbox_test.go b/whatsapp_inbox_test.go index 7e9d3a3..6264d19 100644 --- a/whatsapp_inbox_test.go +++ b/whatsapp_inbox_test.go @@ -17,7 +17,7 @@ func TestWhatsAppPrivateBatchStartsATurnWithAnEmptyReply(t *testing.T) { require.NoError(t, whatsapp.device.Contacts.PutContactName(t.Context(), whatsappTestAna, "Ana", "Ana Souza")) server := newModelFake(t) - server.reply = func(w http.ResponseWriter, call ModelFakeCall) { + server.reply = func(w http.ResponseWriter, _ ModelFakeCall) { modelWriteEvents(w, modelCompletedEvent([]any{modelMessageItem("")}, 100, 0, 5)) } @@ -56,7 +56,7 @@ func TestWhatsAppGroupTurns(t *testing.T) { }{ { name: "plain", - message: func(event *events.Message) { + message: func(_ *events.Message) { }, line: "12:00 Bruno Lima: Who brings the cake?", }, diff --git a/whatsapp_test.go b/whatsapp_test.go index db04dc7..dca137b 100644 --- a/whatsapp_test.go +++ b/whatsapp_test.go @@ -143,7 +143,8 @@ func TestWhatsAppFirstConnectionRetriesStopForLinkChanges(t *testing.T) { { name: "unlink", stop: func(test *WhatsAppRetryTest) { - test.whatsapp.Command("unlink", func(text string) {}) + test.whatsapp.Command("unlink", func(_ string) { + }) }, }, { @@ -183,14 +184,16 @@ func TestWhatsAppPairsAfterFirstConnectionRetriesStop(t *testing.T) { test.fake.connectErr = errors.New("network unavailable") test.start(t) synctest.Wait() - test.whatsapp.Command("unlink", func(text string) {}) + test.whatsapp.Command("unlink", func(_ string) { + }) synctest.Wait() require.False(t, test.whatsapp.isLinked()) test.fake.mutex.Lock() test.fake.connectErr = nil test.fake.mutex.Unlock() - test.whatsapp.Command("pair 15550001111", func(text string) {}) + test.whatsapp.Command("pair 15550001111", func(_ string) { + }) items := <-test.fake.pairings items <- whatsmeow.QRChannelItem{Event: whatsmeow.QRChannelEventCode} synctest.Wait() @@ -298,7 +301,7 @@ func TestWhatsAppIsNotLinkedWithoutALinkedDevice(t *testing.T) { }{ { name: "no session file", - session: func(t *testing.T, dir string) { + session: func(_ *testing.T, _ string) { }, }, {