Skip to content

Commit 7678809

Browse files
committed
fix(cli): fix ESLint unused variable and duplicate import warnings
- Remove unused variables across release files, components, hooks, and utils - Consolidate duplicate imports in e2e test files - Add proper type annotations to mock functions in test files - Remove unused props from component interfaces (textAttributes, width, etc.)
1 parent 69e14fe commit 7678809

File tree

123 files changed

+327
-440
lines changed

Some content is hidden

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

123 files changed

+327
-440
lines changed

cli/release-staging/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,20 @@ function getCurrentVersion() {
114114
if (!fs.existsSync(CONFIG.binaryPath)) return null
115115

116116
try {
117-
return new Promise((resolve, reject) => {
117+
return new Promise((resolve) => {
118118
const child = spawn(CONFIG.binaryPath, ['--version'], {
119119
cwd: CONFIG.packageDir,
120120
stdio: 'pipe',
121121
})
122122

123123
let output = ''
124-
let errorOutput = ''
125124

126125
child.stdout.on('data', (data) => {
127126
output += data.toString()
128127
})
129128

130-
child.stderr.on('data', (data) => {
131-
errorOutput += data.toString()
129+
child.stderr.on('data', () => {
130+
// Ignore stderr output
132131
})
133132

134133
const timeout = setTimeout(() => {

cli/release/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,20 @@ function getCurrentVersion() {
114114
if (!fs.existsSync(CONFIG.binaryPath)) return null
115115

116116
try {
117-
return new Promise((resolve, reject) => {
117+
return new Promise((resolve) => {
118118
const child = spawn(CONFIG.binaryPath, ['--version'], {
119119
cwd: os.homedir(),
120120
stdio: 'pipe',
121121
})
122122

123123
let output = ''
124-
let errorOutput = ''
125124

126125
child.stdout.on('data', (data) => {
127126
output += data.toString()
128127
})
129128

130-
child.stderr.on('data', (data) => {
131-
errorOutput += data.toString()
129+
child.stderr.on('data', () => {
130+
// Ignore stderr output
132131
})
133132

134133
const timeout = setTimeout(() => {

cli/release/postinstall.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env node
22

33
const fs = require('fs');
4-
const path = require('path');
54
const os = require('os');
5+
const path = require('path');
66

77
// Clean up old binary
88
const binaryPath = path.join(

cli/scripts/build-binary.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import {
1111
rmSync,
1212
writeFileSync,
1313
} from 'fs'
14+
import { tmpdir } from 'os'
1415
import { dirname, join } from 'path'
1516
import { fileURLToPath } from 'url'
16-
import { tmpdir } from 'os'
1717

1818
type TargetInfo = {
1919
bunTarget: string

cli/src/__tests__/bash-mode.test.ts

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import type { InputMode } from '../utils/input-modes'
2121
describe('bash-mode', () => {
2222
describe('entering bash mode', () => {
2323
test('typing exactly "!" enters bash mode and clears input', () => {
24-
const setInputMode = mock((_mode: InputMode) => {})
25-
const setInputValue = mock((_value: any) => {})
24+
const setInputMode = mock(() => {})
25+
const setInputValue = mock(() => {})
2626

2727
// Simulate user typing '!'
2828
const inputValue = {
@@ -50,8 +50,8 @@ describe('bash-mode', () => {
5050
})
5151

5252
test('typing "!ls" does NOT enter bash mode (not exactly "!")', () => {
53-
const setInputMode = mock((_mode: InputMode) => {})
54-
const setInputValue = mock((_value: any) => {})
53+
const setInputMode = mock(() => {})
54+
const setInputValue = mock(() => {})
5555

5656
// Simulate user typing '!ls'
5757
const inputValue = {
@@ -78,15 +78,15 @@ describe('bash-mode', () => {
7878
})
7979

8080
test('typing "!" when already in bash mode does nothing special', () => {
81-
const setInputMode = mock((_mode: InputMode) => {})
82-
const setInputValue = mock((_value: any) => {})
81+
const setInputMode = mock(() => {})
82+
const setInputValue = mock(() => {})
8383

8484
const inputValue = {
8585
text: '!',
8686
cursorPosition: 1,
8787
lastEditDueToNav: false,
8888
}
89-
let inputMode = 'bash' as InputMode
89+
const inputMode = 'bash' as InputMode
9090

9191
const userTypedBang = inputMode === ('default' as InputMode) && inputValue.text === '!'
9292

@@ -108,7 +108,7 @@ describe('bash-mode', () => {
108108

109109
describe('exiting bash mode', () => {
110110
test('backspace at cursor position 0 exits bash mode', () => {
111-
const setInputMode = mock((_mode: InputMode) => {})
111+
const setInputMode = mock(() => {})
112112

113113
// Simulate backspace key press in bash mode at cursor position 0
114114
const inputMode: InputMode = 'bash'
@@ -128,7 +128,7 @@ describe('bash-mode', () => {
128128
})
129129

130130
test('backspace at cursor position 0 with non-empty input DOES exit bash mode', () => {
131-
const setInputMode = mock((_mode: InputMode) => {})
131+
const setInputMode = mock(() => {})
132132

133133
const inputMode: InputMode = 'bash'
134134
const cursorPosition = 0
@@ -147,7 +147,7 @@ describe('bash-mode', () => {
147147
})
148148

149149
test('backspace at cursor position > 0 does NOT exit bash mode', () => {
150-
const setInputMode = mock((_mode: InputMode) => {})
150+
const setInputMode = mock(() => {})
151151

152152
const inputMode: InputMode = 'bash'
153153
const cursorPosition: number = 2
@@ -166,7 +166,7 @@ describe('bash-mode', () => {
166166
})
167167

168168
test('other keys at cursor position 0 do NOT exit bash mode', () => {
169-
const setInputMode = mock((_mode: InputMode) => {})
169+
const setInputMode = mock(() => {})
170170

171171
const inputMode: InputMode = 'bash'
172172
const cursorPosition = 0
@@ -185,9 +185,9 @@ describe('bash-mode', () => {
185185
})
186186

187187
test('backspace when NOT in bash mode does nothing to bash mode', () => {
188-
const setInputMode = mock((_mode: InputMode) => {})
188+
const setInputMode = mock(() => {})
189189

190-
let inputMode = 'default' as InputMode
190+
const inputMode = 'default' as InputMode
191191
const cursorPosition = 0
192192
const key = { name: 'backspace' }
193193

@@ -217,12 +217,10 @@ describe('bash-mode', () => {
217217
})
218218

219219
test('normal mode input can contain "!" anywhere', () => {
220-
const inputMode: InputMode = 'default'
221220
const inputValue = 'fix this bug!'
222221

223222
// In normal mode, '!' is just a regular character
224223
expect(inputValue).toContain('!')
225-
expect(inputMode).toBe('default')
226224
})
227225
})
228226

@@ -249,8 +247,7 @@ describe('bash-mode', () => {
249247
})
250248

251249
test('submission saves command WITH "!" to history', () => {
252-
const saveToHistory = mock((_cmd: string) => {})
253-
const inputMode: InputMode = 'bash'
250+
const saveToHistory = mock(() => {})
254251
const trimmedInput = 'git status'
255252
const commandWithBang = '!' + trimmedInput
256253

@@ -261,7 +258,7 @@ describe('bash-mode', () => {
261258
})
262259

263260
test('submission exits bash mode after running command', () => {
264-
const setInputMode = mock((_mode: InputMode) => {})
261+
const setInputMode = mock(() => {})
265262

266263
// After submission, bash mode should be exited
267264
setInputMode('default')
@@ -270,7 +267,7 @@ describe('bash-mode', () => {
270267
})
271268

272269
test('terminal command receives value WITHOUT "!" prefix', () => {
273-
const runTerminalCommand = mock((_params: any) =>
270+
const runTerminalCommand = mock(() =>
274271
Promise.resolve([{ value: { stdout: 'output' } }]),
275272
)
276273
const trimmedInput = 'echo hello'
@@ -293,8 +290,8 @@ describe('bash-mode', () => {
293290
describe('bash mode UI state', () => {
294291
test('input mode is stored separately from input value', () => {
295292
// The inputMode is independent of the input text
296-
const state1 = { inputMode: 'bash' as InputMode, inputValue: 'ls' }
297-
const state2 = { inputMode: 'default' as InputMode, inputValue: 'hello' }
293+
const state1: { inputMode: InputMode; inputValue: string } = { inputMode: 'bash', inputValue: 'ls' }
294+
const state2: { inputMode: InputMode; inputValue: string } = { inputMode: 'default', inputValue: 'hello' }
298295

299296
expect(state1.inputMode).toBe('bash')
300297
expect(state1.inputValue).not.toContain('!')
@@ -305,21 +302,21 @@ describe('bash-mode', () => {
305302

306303
test('input width is adjusted in bash mode for "!" column', () => {
307304
const baseInputWidth = 100
308-
const inputMode: InputMode = 'bash'
305+
const inputModeValue: InputMode = 'bash'
309306

310307
// Width should be reduced by 2 to account for '!' and spacing
311308
const adjustedInputWidth =
312-
inputMode === 'bash' ? baseInputWidth - 2 : baseInputWidth
309+
inputModeValue === 'bash' ? baseInputWidth - 2 : baseInputWidth
313310

314311
expect(adjustedInputWidth).toBe(98)
315312
})
316313

317314
test('input width is NOT adjusted when not in bash mode', () => {
318315
const baseInputWidth = 100
319-
let inputMode = 'default' as InputMode
316+
const inputModeValue = 'default' as InputMode
320317

321318
const adjustedInputWidth =
322-
inputMode === ('bash' as InputMode) ? baseInputWidth - 2 : baseInputWidth
319+
inputModeValue === ('bash' as InputMode) ? baseInputWidth - 2 : baseInputWidth
323320

324321
expect(adjustedInputWidth).toBe(100)
325322
})
@@ -338,7 +335,7 @@ describe('bash-mode', () => {
338335
test('placeholder is normal when not in bash mode', () => {
339336
const normalPlaceholder = 'Ask Buffy anything...'
340337
const bashPlaceholder = 'enter bash command...'
341-
let inputMode = 'default' as InputMode
338+
const inputMode = 'default' as InputMode
342339

343340
const effectivePlaceholder =
344341
inputMode === ('bash' as InputMode) ? bashPlaceholder : normalPlaceholder
@@ -408,7 +405,7 @@ describe('bash-mode', () => {
408405
})
409406

410407
test('normal commands starting with "!" are NOT bash commands', () => {
411-
let inputMode = 'default' as InputMode
408+
const inputMode = 'default' as InputMode
412409
const inputValue = '!ls' // User typed this in normal mode
413410

414411
// This should be treated as a normal prompt, not a bash command
@@ -418,7 +415,7 @@ describe('bash-mode', () => {
418415
})
419416

420417
test('bash mode takes precedence over slash commands', () => {
421-
let inputMode = 'bash' as InputMode
418+
const inputMode = 'bash' as InputMode
422419
const trimmedInput = '/help' // Looks like a slash command
423420

424421
// But in bash mode, it's just a bash command

cli/src/__tests__/e2e-cli.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import { describe, test, expect } from 'bun:test'
21
import { spawn } from 'child_process'
3-
import stripAnsi from 'strip-ansi'
42
import path from 'path'
3+
4+
import { describe, test, expect } from 'bun:test'
5+
import stripAnsi from 'strip-ansi'
6+
7+
58
import { isSDKBuilt, ensureCliTestEnv } from './test-utils'
69

710
const CLI_PATH = path.join(__dirname, '../index.tsx')

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import fs from 'fs'
2+
import os from 'os'
3+
import path from 'path'
4+
15
import {
26
describe,
37
test,
@@ -7,17 +11,17 @@ import {
711
mock,
812
spyOn,
913
} from 'bun:test'
10-
import fs from 'fs'
11-
import os from 'os'
12-
import path from 'path'
1314

1415
import {
1516
saveUserCredentials,
1617
getUserCredentials,
1718
logoutUser,
18-
type User,
1919
} from '../../utils/auth'
2020

21+
import type * as AuthModule from '../../utils/auth'
22+
23+
type User = AuthModule.User
24+
2125
const ORIGINAL_USER: User = {
2226
id: 'user-001',
2327
name: 'CLI Tester',
@@ -49,8 +53,7 @@ describe('Logout and Re-login helpers', () => {
4953
})
5054

5155
const mockConfigPaths = () => {
52-
const authModule =
53-
require('../../utils/auth') as typeof import('../../utils/auth')
56+
const authModule = require('../../utils/auth') as typeof AuthModule
5457
spyOn(authModule, 'getConfigDir').mockReturnValue(tempConfigDir)
5558
spyOn(authModule, 'getCredentialsPath').mockReturnValue(
5659
path.join(tempConfigDir, 'credentials.json'),

cli/src/__tests__/e2e/returning-user-auth.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@ import {
1313
spyOn,
1414
} from 'bun:test'
1515

16+
1617
import { validateApiKey } from '../../hooks/use-auth-query'
1718
import {
1819
getAuthTokenDetails,
1920
saveUserCredentials,
20-
type User,
2121
} from '../../utils/auth'
2222

23+
import type * as AuthModule from '../../utils/auth'
2324
import type { GetUserInfoFromApiKeyFn } from '@codebuff/common/types/contracts/database'
2425
import type { Logger } from '@codebuff/common/types/contracts/logger'
2526

27+
type User = AuthModule.User
28+
2629
const RETURNING_USER: User = {
2730
id: 'returning-user-456',
2831
name: 'Returning User',
@@ -59,8 +62,7 @@ describe('Returning User Authentication helpers', () => {
5962
})
6063

6164
test('should load auth token from credentials file for returning user', () => {
62-
const authModule =
63-
require('../../utils/auth') as typeof import('../../utils/auth')
65+
const authModule = require('../../utils/auth') as typeof AuthModule
6466

6567
spyOn(authModule, 'getConfigDir').mockReturnValue(tempConfigDir)
6668
spyOn(authModule, 'getCredentialsPath').mockReturnValue(
@@ -75,8 +77,7 @@ describe('Returning User Authentication helpers', () => {
7577
})
7678

7779
test('should fall back to CODEBUFF_API_KEY when credentials are missing', () => {
78-
const authModule =
79-
require('../../utils/auth') as typeof import('../../utils/auth')
80+
const authModule = require('../../utils/auth') as typeof AuthModule
8081

8182
spyOn(authModule, 'getConfigDir').mockReturnValue(tempConfigDir)
8283
spyOn(authModule, 'getCredentialsPath').mockReturnValue(
@@ -91,8 +92,7 @@ describe('Returning User Authentication helpers', () => {
9192
})
9293

9394
test('should validate stored credentials without blocking the UI thread', async () => {
94-
const authModule =
95-
require('../../utils/auth') as typeof import('../../utils/auth')
95+
const authModule = require('../../utils/auth') as typeof AuthModule
9696

9797
spyOn(authModule, 'getConfigDir').mockReturnValue(tempConfigDir)
9898
spyOn(authModule, 'getCredentialsPath').mockReturnValue(

cli/src/__tests__/helpers/mock-api-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { mock } from 'bun:test'
22

3-
import type { CodebuffApiClient, ApiResponse } from '../../utils/codebuff-api'
3+
import type { CodebuffApiClient } from '../../utils/codebuff-api'
44

55
export interface MockApiClientOverrides {
66
get?: ReturnType<typeof mock>

cli/src/__tests__/integration-tmux.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
import { describe, test, expect, beforeAll } from 'bun:test'
21
import { spawn } from 'child_process'
3-
import stripAnsi from 'strip-ansi'
42
import path from 'path'
3+
4+
import { describe, test, expect, beforeAll } from 'bun:test'
5+
import stripAnsi from 'strip-ansi'
6+
7+
58
import {
69
isTmuxAvailable,
710
isSDKBuilt,

0 commit comments

Comments
 (0)