Skip to content

Commit 186b29a

Browse files
committed
Fix linter errors: Replace 'any' types with proper TypeScript types
- Replace 'any' with 'unknown as vscode.ExtensionContext' for mock contexts - Use vi.mocked() instead of casting to 'any' for mock functions - Replace 'any' with proper type annotations for function parameters - Fixes all 16 ESLint warnings about @typescript-eslint/no-explicit-any Addresses feedback from @cte in PR comment
1 parent 2170f58 commit 186b29a

File tree

4 files changed

+356
-16
lines changed

4 files changed

+356
-16
lines changed

packages/cloud/src/TelemetryClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class TelemetryClient extends BaseTelemetryClient {
2929
*/
3030
public initializeRetryQueue(context: vscode.ExtensionContext): void {
3131
this.context = context
32-
const retrySettings = context.globalState.get("telemetryRetrySettings") as any
32+
const retrySettings = context.globalState.get("telemetryRetrySettings") as Record<string, unknown> | undefined
3333
this.retryQueue = new TelemetryRetryQueue(context, retrySettings)
3434

3535
// Start periodic retry processing

packages/telemetry/src/__tests__/ResilientTelemetryClient.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe("ResilientTelemetryClient", () => {
4747
get: vi.fn().mockReturnValue([]),
4848
update: vi.fn().mockResolvedValue(undefined),
4949
},
50-
} as any
50+
} as unknown as vscode.ExtensionContext
5151

5252
resilientClient = new ResilientTelemetryClient(mockWrappedClient, mockContext)
5353
})
@@ -97,7 +97,7 @@ describe("ResilientTelemetryClient", () => {
9797
}
9898

9999
// Make wrapped client throw error
100-
;(mockWrappedClient.capture as any).mockRejectedValue(new Error("Network error"))
100+
vi.mocked(mockWrappedClient.capture).mockRejectedValue(new Error("Network error"))
101101

102102
await resilientClient.capture(event)
103103

@@ -112,7 +112,7 @@ describe("ResilientTelemetryClient", () => {
112112
}
113113

114114
// Make wrapped client fail
115-
;(mockWrappedClient.capture as any).mockRejectedValue(new Error("Network error"))
115+
vi.mocked(mockWrappedClient.capture).mockRejectedValue(new Error("Network error"))
116116

117117
await resilientClient.capture(highPriorityEvent)
118118

@@ -125,7 +125,7 @@ describe("ResilientTelemetryClient", () => {
125125
properties: { taskId: "test" },
126126
}
127127

128-
;(mockWrappedClient.isTelemetryEnabled as any).mockReturnValue(false)
128+
vi.mocked(mockWrappedClient.isTelemetryEnabled).mockReturnValue(false)
129129

130130
await resilientClient.capture(event)
131131

@@ -137,7 +137,7 @@ describe("ResilientTelemetryClient", () => {
137137

138138
describe("delegation methods", () => {
139139
it("should delegate setProvider to wrapped client", () => {
140-
const mockProvider = {} as any
140+
const mockProvider = {} as Parameters<typeof mockWrappedClient.setProvider>[0]
141141
resilientClient.setProvider(mockProvider)
142142

143143
expect(mockWrappedClient.setProvider).toHaveBeenCalledWith(mockProvider)
@@ -157,7 +157,7 @@ describe("ResilientTelemetryClient", () => {
157157
})
158158

159159
it("should return subscription from wrapped client", () => {
160-
const mockSubscription = { type: "exclude", events: [] } as any
160+
const mockSubscription = { type: "exclude", events: [] } as typeof mockWrappedClient.subscription
161161
mockWrappedClient.subscription = mockSubscription
162162

163163
expect(resilientClient.subscription).toBe(mockSubscription)
@@ -219,7 +219,7 @@ describe("ResilientTelemetryClient", () => {
219219
}
220220

221221
// Make wrapped client fail to trigger queueing
222-
;(mockWrappedClient.capture as any).mockRejectedValue(new Error("Network error"))
222+
vi.mocked(mockWrappedClient.capture).mockRejectedValue(new Error("Network error"))
223223

224224
await resilientClient.capture(event)
225225

packages/telemetry/src/__tests__/TelemetryRetryQueue.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe("TelemetryRetryQueue", () => {
3838
get: vi.fn().mockReturnValue([]),
3939
update: vi.fn().mockResolvedValue(undefined),
4040
},
41-
} as any
41+
} as unknown as vscode.ExtensionContext
4242

4343
retryQueue = new TelemetryRetryQueue(mockContext)
4444
})
@@ -97,7 +97,7 @@ describe("TelemetryRetryQueue", () => {
9797
await retryQueue.enqueue(highEvent, "high")
9898

9999
// High priority event should be inserted before normal priority
100-
const calls = (mockContext.globalState.update as any).mock.calls
100+
const calls = vi.mocked(mockContext.globalState.update).mock.calls
101101
const lastCall = calls[calls.length - 1]
102102
const queue = lastCall[1]
103103

@@ -131,7 +131,7 @@ describe("TelemetryRetryQueue", () => {
131131
}
132132

133133
// Mock existing queue with one event
134-
;(mockContext.globalState.get as any).mockReturnValue([
134+
vi.mocked(mockContext.globalState.get).mockReturnValue([
135135
{
136136
id: "test-id",
137137
event,
@@ -165,15 +165,15 @@ describe("TelemetryRetryQueue", () => {
165165
priority: "normal",
166166
}
167167

168-
;(mockContext.globalState.get as any).mockReturnValue([queuedEvent])
168+
vi.mocked(mockContext.globalState.get).mockReturnValue([queuedEvent])
169169

170170
const sendFunction = vi.fn().mockResolvedValue(false) // Failure
171171

172172
await retryQueue.processQueue(sendFunction)
173173

174174
expect(sendFunction).toHaveBeenCalledWith(event)
175175

176-
const updateCalls = (mockContext.globalState.update as any).mock.calls
176+
const updateCalls = vi.mocked(mockContext.globalState.update).mock.calls
177177
const lastCall = updateCalls[updateCalls.length - 1]
178178
const updatedQueue = lastCall[1]
179179

@@ -196,7 +196,7 @@ describe("TelemetryRetryQueue", () => {
196196
priority: "normal",
197197
}
198198

199-
;(mockContext.globalState.get as any).mockReturnValue([queuedEvent])
199+
vi.mocked(mockContext.globalState.get).mockReturnValue([queuedEvent])
200200

201201
const sendFunction = vi.fn().mockResolvedValue(false) // Failure
202202

@@ -218,7 +218,7 @@ describe("TelemetryRetryQueue", () => {
218218
priority: "normal" as const,
219219
}))
220220

221-
;(mockContext.globalState.get as any).mockReturnValue(events)
221+
vi.mocked(mockContext.globalState.get).mockReturnValue(events)
222222

223223
const sendFunction = vi.fn().mockResolvedValue(true)
224224

@@ -236,7 +236,7 @@ describe("TelemetryRetryQueue", () => {
236236
{ id: "2", event: {}, timestamp: 0, retryCount: 0, nextRetryAt: 0, priority: "normal" },
237237
]
238238

239-
;(mockContext.globalState.get as any).mockReturnValue(events)
239+
vi.mocked(mockContext.globalState.get).mockReturnValue(events)
240240

241241
const size = await retryQueue.getQueueSize()
242242
expect(size).toBe(2)

0 commit comments

Comments
 (0)