Skip to content

Commit 70812c3

Browse files
committed
Clean up ESLint no-unused-vars warnings across codebase
- Prefix unused variables with _ to indicate intentional non-use - Remove unused type definitions and interfaces - Remove dead code (unused functions, duplicate calculations) - Add typed mock utilities in common/src/testing/mock-types.ts Reduces ESLint warnings from 214 to 88 (59% reduction)
1 parent a5c8873 commit 70812c3

File tree

95 files changed

+406
-274
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+406
-274
lines changed

agents/__tests__/context-pruner.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,13 @@ const createToolResultMessage = (
185185
content: [
186186
{
187187
type: 'json',
188-
value: value as any,
188+
value: value as Record<string, unknown>,
189189
},
190190
],
191191
})
192192

193193
describe('context-pruner handleSteps', () => {
194-
let mockAgentState: any
194+
let mockAgentState: { messageHistory: Message[]; contextTokenCount: number }
195195

196196
beforeEach(() => {
197197
mockAgentState = {
@@ -675,7 +675,7 @@ describe('context-pruner handleSteps', () => {
675675
})
676676

677677
describe('context-pruner long message truncation', () => {
678-
let mockAgentState: any
678+
let mockAgentState: { messageHistory: Message[]; contextTokenCount: number }
679679

680680
beforeEach(() => {
681681
mockAgentState = {
@@ -772,7 +772,7 @@ describe('context-pruner long message truncation', () => {
772772
})
773773

774774
describe('context-pruner code_search with flags', () => {
775-
let mockAgentState: any
775+
let mockAgentState: { messageHistory: Message[]; contextTokenCount: number }
776776

777777
beforeEach(() => {
778778
mockAgentState = {
@@ -824,7 +824,7 @@ describe('context-pruner code_search with flags', () => {
824824
})
825825

826826
describe('context-pruner ask_user with questions and answers', () => {
827-
let mockAgentState: any
827+
let mockAgentState: { messageHistory: Message[]; contextTokenCount: number }
828828

829829
beforeEach(() => {
830830
mockAgentState = {
@@ -937,7 +937,7 @@ describe('context-pruner ask_user with questions and answers', () => {
937937
})
938938

939939
describe('context-pruner terminal command exit codes', () => {
940-
let mockAgentState: any
940+
let mockAgentState: { messageHistory: Message[]; contextTokenCount: number }
941941

942942
beforeEach(() => {
943943
mockAgentState = {
@@ -1009,7 +1009,7 @@ describe('context-pruner terminal command exit codes', () => {
10091009
})
10101010

10111011
describe('context-pruner spawn_agents with prompt and params', () => {
1012-
let mockAgentState: any
1012+
let mockAgentState: { messageHistory: Message[]; contextTokenCount: number }
10131013

10141014
beforeEach(() => {
10151015
mockAgentState = {
@@ -1128,7 +1128,7 @@ describe('context-pruner spawn_agents with prompt and params', () => {
11281128
})
11291129

11301130
describe('context-pruner repeated compaction', () => {
1131-
let mockAgentState: any
1131+
let mockAgentState: { messageHistory: Message[]; contextTokenCount: number }
11321132

11331133
beforeEach(() => {
11341134
mockAgentState = {
@@ -1306,7 +1306,7 @@ First assistant response
13061306
})
13071307

13081308
describe('context-pruner image token counting', () => {
1309-
let mockAgentState: any
1309+
let mockAgentState: { messageHistory: Message[]; contextTokenCount: number }
13101310

13111311
beforeEach(() => {
13121312
mockAgentState = {
@@ -1371,7 +1371,7 @@ describe('context-pruner image token counting', () => {
13711371
})
13721372

13731373
describe('context-pruner threshold behavior', () => {
1374-
let mockAgentState: any
1374+
let mockAgentState: { messageHistory: Message[]; contextTokenCount: number }
13751375

13761376
beforeEach(() => {
13771377
mockAgentState = {
@@ -1444,7 +1444,7 @@ describe('context-pruner threshold behavior', () => {
14441444
})
14451445

14461446
describe('context-pruner str_replace and write_file tool results', () => {
1447-
let mockAgentState: any
1447+
let mockAgentState: { messageHistory: Message[]; contextTokenCount: number }
14481448

14491449
beforeEach(() => {
14501450
mockAgentState = {
@@ -1561,7 +1561,7 @@ describe('context-pruner str_replace and write_file tool results', () => {
15611561
})
15621562

15631563
describe('context-pruner glob and list_directory tools', () => {
1564-
let mockAgentState: any
1564+
let mockAgentState: { messageHistory: Message[]; contextTokenCount: number }
15651565

15661566
beforeEach(() => {
15671567
mockAgentState = {

agents/e2e/file-explorer.e2e.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ export class AuthService {
284284
}
285285

286286
// Use local agent definitions to test the updated handleSteps
287-
const localFilePickerDef = filePickerDefinition as unknown as any
288-
const localFileListerDef = fileListerDefinition as unknown as any
287+
const localFilePickerDef = filePickerDefinition
288+
const localFileListerDef = fileListerDefinition
289289

290290
const client = new CodebuffClient({
291291
apiKey,

cli/src/__tests__/e2e/first-time-login.test.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, test, expect, mock } from 'bun:test'
22

3+
import { createMockLogger } from '@codebuff/common/testing/mock-types'
34
import {
45
generateLoginUrl,
56
pollLoginStatus,
@@ -8,22 +9,10 @@ import {
89
import { createMockApiClient } from '../helpers/mock-api-client'
910

1011
import type { ApiResponse } from '../../utils/codebuff-api'
11-
import type { Logger } from '@codebuff/common/types/contracts/logger'
12-
13-
type MockLogger = {
14-
[K in keyof Logger]: ReturnType<typeof mock> & Logger[K]
15-
}
16-
17-
const createLogger = (): MockLogger => ({
18-
info: mock(() => {}) as ReturnType<typeof mock> & Logger['info'],
19-
error: mock(() => {}) as ReturnType<typeof mock> & Logger['error'],
20-
warn: mock(() => {}) as ReturnType<typeof mock> & Logger['warn'],
21-
debug: mock(() => {}) as ReturnType<typeof mock> & Logger['debug'],
22-
})
2312

2413
describe('First-Time Login Flow (helpers)', () => {
2514
test('generateLoginUrl posts fingerprint id and returns payload', async () => {
26-
const logger = createLogger()
15+
const logger = createMockLogger()
2716
const responsePayload: LoginUrlResponse = {
2817
loginUrl: 'https://cli.test/login?code=abc123',
2918
fingerprintHash: 'hash-123',
@@ -51,7 +40,7 @@ describe('First-Time Login Flow (helpers)', () => {
5140
})
5241

5342
test('pollLoginStatus resolves with user after handling transient 401 responses', async () => {
54-
const logger = createLogger()
43+
const logger = createMockLogger()
5544
const apiResponses: Array<ApiResponse<{ user?: unknown }>> = [
5645
{ ok: false, status: 401 },
5746
{ ok: false, status: 401 },
@@ -114,7 +103,7 @@ describe('First-Time Login Flow (helpers)', () => {
114103
})
115104

116105
test('pollLoginStatus times out when user never appears', async () => {
117-
const logger = createLogger()
106+
const logger = createMockLogger()
118107
let nowTime = 0
119108
const intervalMs = 5000
120109
const timeoutMs = 20000
@@ -151,7 +140,7 @@ describe('First-Time Login Flow (helpers)', () => {
151140
})
152141

153142
test('pollLoginStatus stops when caller aborts', async () => {
154-
const logger = createLogger()
143+
const logger = createMockLogger()
155144
const loginStatusMock = mock(async () => {
156145
return { ok: false, status: 401 } as ApiResponse<{ user?: unknown }>
157146
})

cli/src/__tests__/e2e/logout-relogin-flow.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ describe('Logout and Re-login helpers', () => {
6565
const mockLogoutApi = () => {
6666
spyOn(CodebuffApiModule, 'getApiClient').mockReturnValue({
6767
logout: async () => ({ ok: true, status: 200 }),
68-
} as any)
68+
} as ReturnType<typeof CodebuffApiModule.getApiClient>)
6969
}
7070

7171
test('logoutUser removes credentials file and returns true', async () => {

cli/src/__tests__/integration/login-polling-working.test.ts

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
import { describe, test, expect, mock } from 'bun:test'
22

3+
import { createMockLogger } from '@codebuff/common/testing/mock-types'
34
import { generateLoginUrl, pollLoginStatus } from '../../login/login-flow'
45
import { createMockApiClient } from '../helpers/mock-api-client'
56

67
import type { LoginUrlResponse } from '../../login/login-flow'
78
import type { ApiResponse } from '../../utils/codebuff-api'
89
import type { Logger } from '@codebuff/common/types/contracts/logger'
910

10-
type MockLogger = {
11-
[K in keyof Logger]: ReturnType<typeof mock> & Logger[K]
12-
}
13-
14-
const createLogger = (): MockLogger => ({
15-
info: mock(() => {}) as ReturnType<typeof mock> & Logger['info'],
16-
error: mock(() => {}) as ReturnType<typeof mock> & Logger['error'],
17-
warn: mock(() => {}) as ReturnType<typeof mock> & Logger['warn'],
18-
debug: mock(() => {}) as ReturnType<typeof mock> & Logger['debug'],
19-
})
20-
2111
const createClock = () => {
2212
let current = 0
2313
return {
@@ -30,7 +20,7 @@ const createClock = () => {
3020

3121
describe('Login Polling (Working)', () => {
3222
test('P0: Polling Lifecycle - should stop polling and return user when login succeeds', async () => {
33-
const logger = createLogger()
23+
const logger = createMockLogger()
3424
const apiResponses: Array<ApiResponse<{ user?: unknown }>> = [
3525
{ ok: false, status: 401 },
3626
{
@@ -85,7 +75,7 @@ describe('Login Polling (Working)', () => {
8575
})
8676

8777
test('P0: Polling Lifecycle - should keep polling on 401 responses', async () => {
88-
const logger = createLogger()
78+
const logger = createMockLogger()
8979
const loginStatusMock = mock(async () => {
9080
return { ok: false, status: 401 } as ApiResponse<{ user?: unknown }>
9181
})
@@ -114,7 +104,7 @@ describe('Login Polling (Working)', () => {
114104
})
115105

116106
test('P0: Polling Lifecycle - should call loginStatus with full metadata', async () => {
117-
const logger = createLogger()
107+
const logger = createMockLogger()
118108
const loginStatusMock = mock(
119109
async (req: {
120110
fingerprintId: string
@@ -161,7 +151,7 @@ describe('Login Polling (Working)', () => {
161151
})
162152

163153
test('P1: Error Handling - should log warnings on non-401 responses but continue polling', async () => {
164-
const logger = createLogger()
154+
const logger = createMockLogger()
165155
const loginStatusMock = mock(async () => {
166156
return { ok: false, status: 500, error: 'Server Error' } as ApiResponse<{
167157
user?: unknown
@@ -192,7 +182,7 @@ describe('Login Polling (Working)', () => {
192182
})
193183

194184
test('P1: Error Handling - should swallow network errors and keep polling', async () => {
195-
const logger = createLogger()
185+
const logger = createMockLogger()
196186
let attempt = 0
197187
const loginStatusMock = mock(async () => {
198188
attempt += 1
@@ -242,13 +232,13 @@ describe('Login Polling (Working)', () => {
242232
if (!payload || typeof payload !== 'object') {
243233
return false
244234
}
245-
return JSON.stringify(payload as any).includes('network failed')
235+
return JSON.stringify(payload as Parameters<Logger['error']>[0]).includes('network failed')
246236
})
247237
expect(sawNetworkFailure).toBe(true)
248238
})
249239

250240
test('P0: generateLoginUrl wrapper - should hit backend and return payload', async () => {
251-
const logger = createLogger()
241+
const logger = createMockLogger()
252242
const payload: LoginUrlResponse = {
253243
loginUrl: 'https://cli.test/login?code=code-123',
254244
fingerprintHash: 'hash-123',
@@ -274,7 +264,7 @@ describe('Login Polling (Working)', () => {
274264
})
275265

276266
test('P0: generateLoginUrl wrapper - should throw when backend returns error', async () => {
277-
const logger = createLogger()
267+
const logger = createMockLogger()
278268
const loginCodeMock = mock(async () => {
279269
return {
280270
ok: false,

cli/src/chat.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,18 @@ import { useShallow } from 'zustand/react/shallow'
1313
import { getAdsEnabled } from './commands/ads'
1414
import { routeUserPrompt, addBashMessageToHistory } from './commands/router'
1515
import { AdBanner } from './components/ad-banner'
16-
import { ChatInputBar } from './components/chat-input-bar'
1716
import { BottomStatusLine } from './components/bottom-status-line'
18-
import { areCreditsRestored } from './components/out-of-credits-banner'
17+
import { ChatInputBar } from './components/chat-input-bar'
1918
import { LoadPreviousButton } from './components/load-previous-button'
2019
import { MessageWithAgents } from './components/message-with-agents'
20+
import { areCreditsRestored } from './components/out-of-credits-banner'
2121
import { PendingBashMessage } from './components/pending-bash-message'
2222
import { StatusBar } from './components/status-bar'
2323
import { TopBanner } from './components/top-banner'
2424
import { getSlashCommandsWithSkills } from './data/slash-commands'
2525
import { useAgentValidation } from './hooks/use-agent-validation'
2626
import { useAskUserBridge } from './hooks/use-ask-user-bridge'
2727
import { useChatInput } from './hooks/use-chat-input'
28-
import { useClaudeQuotaQuery } from './hooks/use-claude-quota-query'
2928
import {
3029
useChatKeyboard,
3130
type ChatKeyboardHandlers,
@@ -34,26 +33,25 @@ import { useChatMessages } from './hooks/use-chat-messages'
3433
import { useChatState } from './hooks/use-chat-state'
3534
import { useChatStreaming } from './hooks/use-chat-streaming'
3635
import { useChatUI } from './hooks/use-chat-ui'
36+
import { useClaudeQuotaQuery } from './hooks/use-claude-quota-query'
3737
import { useClipboard } from './hooks/use-clipboard'
38-
import { useGravityAd } from './hooks/use-gravity-ad'
3938
import { useEvent } from './hooks/use-event'
39+
import { useGravityAd } from './hooks/use-gravity-ad'
4040
import { useInputHistory } from './hooks/use-input-history'
4141
import { usePublishMutation } from './hooks/use-publish-mutation'
4242
import { useSendMessage } from './hooks/use-send-message'
4343
import { useSuggestionEngine } from './hooks/use-suggestion-engine'
4444
import { useUsageMonitor } from './hooks/use-usage-monitor'
4545
import { WEBSITE_URL } from './login/constants'
4646
import { getProjectRoot } from './project-files'
47-
import { useChatStore } from './state/chat-store'
4847
import { useChatHistoryStore } from './state/chat-history-store'
48+
import { useChatStore } from './state/chat-store'
4949
import { useFeedbackStore } from './state/feedback-store'
5050
import { useMessageBlockStore } from './state/message-block-store'
5151
import { usePublishStore } from './state/publish-store'
52-
import {
53-
addClipboardPlaceholder,
54-
addPendingImageFromFile,
55-
validateAndAddImage,
56-
} from './utils/pending-attachments'
52+
import { reportActivity } from './utils/activity-tracker'
53+
import { trackEvent } from './utils/analytics'
54+
import { getClaudeOAuthStatus } from './utils/claude-oauth'
5755
import { showClipboardMessage } from './utils/clipboard'
5856
import { readClipboardImage } from './utils/clipboard-image'
5957
import { getInputModeConfig } from './utils/input-modes'
@@ -62,22 +60,24 @@ import {
6260
createDefaultChatKeyboardState,
6361
} from './utils/keyboard-actions'
6462
import { loadLocalAgents } from './utils/local-agent-registry'
63+
import { logger } from './utils/logger'
64+
import {
65+
addClipboardPlaceholder,
66+
addPendingImageFromFile,
67+
validateAndAddImage,
68+
} from './utils/pending-attachments'
6569
import { getLoadedSkills } from './utils/skill-registry'
6670
import {
6771
getStatusIndicatorState,
6872
type AuthStatus,
6973
} from './utils/status-indicator-state'
70-
import { getClaudeOAuthStatus } from './utils/claude-oauth'
7174
import { createPasteHandler } from './utils/strings'
72-
import { computeInputLayoutMetrics } from './utils/text-layout'
73-
import { reportActivity } from './utils/activity-tracker'
74-
import { trackEvent } from './utils/analytics'
75-
import { logger } from './utils/logger'
7675
import { setTerminalTitle } from './utils/terminal-title'
76+
import { computeInputLayoutMetrics } from './utils/text-layout'
7777

7878
import type { CommandResult } from './commands/command-registry'
79-
import type { MatchedSlashCommand } from './hooks/use-suggestion-engine'
8079
import type { MultilineInputHandle } from './components/multiline-input'
80+
import type { MatchedSlashCommand } from './hooks/use-suggestion-engine'
8181
import type { User } from './utils/auth'
8282
import type { AgentMode } from './utils/constants'
8383
import type { FileTreeNode } from '@codebuff/common/util/file'

cli/src/commands/__tests__/bash-command.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('bash command', () => {
3030
inputValue: '/bash',
3131
isChainInProgressRef: { current: false },
3232
isStreaming: false,
33-
logoutMutation: {} as any,
33+
logoutMutation: {} as RouterParams['logoutMutation'],
3434
streamMessageIdRef: { current: null },
3535
addToQueue: mock(() => {}),
3636
clearMessages: mock(() => {}),
@@ -298,7 +298,7 @@ describe('bash command', () => {
298298
inputValue: '/bash',
299299
isChainInProgressRef: { current: false },
300300
isStreaming: false,
301-
logoutMutation: {} as any,
301+
logoutMutation: {} as RouterParams['logoutMutation'],
302302
streamMessageIdRef: { current: null },
303303
addToQueue: mock(() => {}),
304304
clearMessages: mock(() => {}),

cli/src/components/login-modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { useLoginPolling } from '../hooks/use-login-polling'
1010
import { useLogo } from '../hooks/use-logo'
1111
import { useSheenAnimation } from '../hooks/use-sheen-animation'
1212
import { useTheme } from '../hooks/use-theme'
13-
import { getLogoBlockColor, getLogoAccentColor } from '../utils/theme-system'
1413
import {
1514
formatUrl,
1615
generateFingerprintId,
@@ -19,6 +18,7 @@ import {
1918
import { useLoginStore } from '../state/login-store'
2019
import { copyTextToClipboard } from '../utils/clipboard'
2120
import { logger } from '../utils/logger'
21+
import { getLogoBlockColor, getLogoAccentColor } from '../utils/theme-system'
2222

2323
import type { User } from '../utils/auth'
2424

0 commit comments

Comments
 (0)