Skip to content

Commit 3d988e1

Browse files
types: remove production explicit-any suppressions (#1846)
## Summary Production-only cleanup toward #965. - Remove broad production `no-explicit-any` suppressions and type the affected code, retaining one documented, line-scoped `any[]` for forwarding warning-message overloads unchanged. Public warning overloads remain fully typed. - Use concrete event types, `void` callback returns, and generic receiver/argument types in API wrappers. Preserve warning-message overloads and retain `unknown` only at genuinely untyped API or caught-value boundaries. - Narrow project-picker values and validate package-picker button selections against the actual picker items. - Add 26 regression tests for typed wrappers, warning overloads, picker navigation, cancellation, and package selection. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 68648f4 commit 3d988e1

11 files changed

Lines changed: 400 additions & 73 deletions

File tree

‎src/common/command.api.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
/* eslint-disable @typescript-eslint/no-explicit-any */
21
import { commands } from 'vscode';
32
import { Disposable } from 'vscode-jsonrpc';
43

5-
export function registerCommand(command: string, callback: (...args: any[]) => any, thisArg?: any): Disposable {
4+
/** Registers a command with inferred callback arguments and an optional receiver. */
5+
export function registerCommand<TArgs extends unknown[], TResult, TThis = void>(
6+
command: string,
7+
callback: (this: TThis, ...args: TArgs) => TResult,
8+
thisArg?: TThis,
9+
): Disposable {
610
return commands.registerCommand(command, callback, thisArg);
711
}
812

9-
export function executeCommand<T = unknown>(command: string, ...rest: any[]): Thenable<T> {
13+
/** Executes a command with its arguments; callers specify the expected result type. */
14+
export function executeCommand<T = unknown>(command: string, ...rest: unknown[]): Thenable<T> {
1015
return commands.executeCommand(command, ...rest);
1116
}

‎src/common/extension.apis.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
/* eslint-disable @typescript-eslint/no-explicit-any */
21
import { Extension, extensions } from 'vscode';
32

4-
export function getExtension<T = any>(extensionId: string): Extension<T> | undefined {
5-
return extensions.getExtension(extensionId);
3+
/** Looks up an extension by ID; callers specify its exported API type when needed. */
4+
export function getExtension<T = unknown>(extensionId: string): Extension<T> | undefined {
5+
return extensions.getExtension<T>(extensionId);
66
}
77

8-
export function allExtensions(): readonly Extension<any>[] {
8+
/** Returns installed extensions without assuming a shared exported API type. */
9+
export function allExtensions(): readonly Extension<unknown>[] {
910
return extensions.all;
1011
}

‎src/common/pickers/managers.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
commands,
32
QuickInputButtons,
43
QuickPickItem,
54
QuickPickItemKind,
@@ -12,6 +11,7 @@ import type {
1211
InternalEnvironmentManager,
1312
InternalPackageManager,
1413
} from '../../managers/common/registeredManagers';
14+
import { executeCommand } from '../command.api';
1515
import { Common, Interpreter, Pickers } from '../localize';
1616
import { showQuickPickWithButtons } from '../window.apis';
1717

@@ -262,8 +262,10 @@ export async function newProjectSelection(creators: PythonProjectCreator[]): Pro
262262
return undefined;
263263
}
264264
// Handle back button
265-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
266-
if ((newSelected as any)?.kind === -1 || (newSelected as any)?.back === true) {
265+
if (
266+
!Array.isArray(newSelected) &&
267+
(newSelected.kind === QuickPickItemKind.Separator || ('back' in newSelected && newSelected.back === true))
268+
) {
267269
// User pressed the back button, re-show the first menu
268270
return pickCreator(creators);
269271
}
@@ -273,7 +275,7 @@ export async function newProjectSelection(creators: PythonProjectCreator[]): Pro
273275
return selectedCreator?.c;
274276
} catch (ex) {
275277
if (ex === QuickInputButtons.Back) {
276-
await commands.executeCommand('python-envs.addPythonProject');
278+
await executeCommand('python-envs.addPythonProject');
277279
}
278280
}
279281
}

‎src/common/window.apis.ts‎

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-explicit-any */
21
import {
32
CancellationToken,
43
Disposable,
@@ -43,17 +42,19 @@ export function createTerminal(options: ExtensionTerminalOptions | TerminalOptio
4342
return window.createTerminal(options);
4443
}
4544

46-
export function onDidChangeTerminalShellIntegration(
47-
listener: (e: TerminalShellIntegrationChangeEvent) => any,
48-
thisArgs?: any,
45+
/** Subscribes to shell integration changes, binding the listener to the optional receiver. */
46+
export function onDidChangeTerminalShellIntegration<TThis = void>(
47+
listener: (this: TThis, e: TerminalShellIntegrationChangeEvent) => void,
48+
thisArgs?: TThis,
4949
disposables?: Disposable[],
5050
): Disposable {
5151
return window.onDidChangeTerminalShellIntegration(listener, thisArgs, disposables);
5252
}
5353

54-
export function onDidWriteTerminalData(
55-
listener: (e: { readonly terminal: Terminal; readonly data: string }) => any,
56-
thisArgs?: any,
54+
/** Subscribes to terminal data, binding the listener to the optional receiver. */
55+
export function onDidWriteTerminalData<TThis = void>(
56+
listener: (this: TThis, e: { readonly terminal: Terminal; readonly data: string }) => void,
57+
thisArgs?: TThis,
5758
disposables?: Disposable[],
5859
): Disposable {
5960
return window.onDidWriteTerminalData(listener, thisArgs, disposables);
@@ -79,57 +80,64 @@ export function activeTextEditor(): TextEditor | undefined {
7980
return window.activeTextEditor;
8081
}
8182

82-
export function onDidChangeActiveTerminal(
83-
listener: (e: Terminal | undefined) => any,
84-
thisArgs?: any,
83+
/** Subscribes to active terminal changes, binding the listener to the optional receiver. */
84+
export function onDidChangeActiveTerminal<TThis = void>(
85+
listener: (this: TThis, e: Terminal | undefined) => void,
86+
thisArgs?: TThis,
8587
disposables?: Disposable[],
8688
): Disposable {
8789
return window.onDidChangeActiveTerminal(listener, thisArgs, disposables);
8890
}
8991

90-
export function onDidChangeActiveTextEditor(
91-
listener: (e: TextEditor | undefined) => any,
92-
thisArgs?: any,
92+
/** Subscribes to active editor changes, binding the listener to the optional receiver. */
93+
export function onDidChangeActiveTextEditor<TThis = void>(
94+
listener: (this: TThis, e: TextEditor | undefined) => void,
95+
thisArgs?: TThis,
9396
disposables?: Disposable[],
9497
): Disposable {
9598
return window.onDidChangeActiveTextEditor(listener, thisArgs, disposables);
9699
}
97100

98-
export function onDidStartTerminalShellExecution(
99-
listener: (e: TerminalShellExecutionStartEvent) => any,
100-
thisArgs?: any,
101+
/** Subscribes to shell execution starts, binding the listener to the optional receiver. */
102+
export function onDidStartTerminalShellExecution<TThis = void>(
103+
listener: (this: TThis, e: TerminalShellExecutionStartEvent) => void,
104+
thisArgs?: TThis,
101105
disposables?: Disposable[],
102106
): Disposable {
103107
return window.onDidStartTerminalShellExecution(listener, thisArgs, disposables);
104108
}
105109

106-
export function onDidEndTerminalShellExecution(
107-
listener: (e: TerminalShellExecutionEndEvent) => any,
108-
thisArgs?: any,
110+
/** Subscribes to shell execution completion, binding the listener to the optional receiver. */
111+
export function onDidEndTerminalShellExecution<TThis = void>(
112+
listener: (this: TThis, e: TerminalShellExecutionEndEvent) => void,
113+
thisArgs?: TThis,
109114
disposables?: Disposable[],
110115
): Disposable {
111116
return window.onDidEndTerminalShellExecution(listener, thisArgs, disposables);
112117
}
113118

114-
export function onDidOpenTerminal(
115-
listener: (terminal: Terminal) => any,
116-
thisArgs?: any,
119+
/** Subscribes to opened terminals, binding the listener to the optional receiver. */
120+
export function onDidOpenTerminal<TThis = void>(
121+
listener: (this: TThis, terminal: Terminal) => void,
122+
thisArgs?: TThis,
117123
disposables?: Disposable[],
118124
): Disposable {
119125
return window.onDidOpenTerminal(listener, thisArgs, disposables);
120126
}
121127

122-
export function onDidCloseTerminal(
123-
listener: (terminal: Terminal) => any,
124-
thisArgs?: any,
128+
/** Subscribes to closed terminals, binding the listener to the optional receiver. */
129+
export function onDidCloseTerminal<TThis = void>(
130+
listener: (this: TThis, terminal: Terminal) => void,
131+
thisArgs?: TThis,
125132
disposables?: Disposable[],
126133
): Disposable {
127134
return window.onDidCloseTerminal(listener, thisArgs, disposables);
128135
}
129136

130-
export function onDidChangeTerminalState(
131-
listener: (e: Terminal) => any,
132-
thisArgs?: any,
137+
/** Subscribes to terminal state changes, binding the listener to the optional receiver. */
138+
export function onDidChangeTerminalState<TThis = void>(
139+
listener: (this: TThis, e: Terminal) => void,
140+
thisArgs?: TThis,
133141
disposables?: Disposable[],
134142
): Disposable {
135143
return window.onDidChangeTerminalState(listener, thisArgs, disposables);
@@ -340,6 +348,7 @@ export function showErrorMessage<T extends MessageItem>(
340348
return window.showErrorMessage(message, options, ...items);
341349
}
342350

351+
/** Shows a warning with optional options and actions, returning the selected action unchanged. */
343352
export function showWarningMessage<T extends string>(message: string, ...items: T[]): Thenable<T | undefined>;
344353
export function showWarningMessage<T extends string>(
345354
message: string,
@@ -352,8 +361,9 @@ export function showWarningMessage<T extends MessageItem>(
352361
options: MessageOptions,
353362
...items: T[]
354363
): Thenable<T | undefined>;
355-
export function showWarningMessage(message: string, ...items: any[]): Thenable<string | undefined> {
356-
return window.showWarningMessage(message, ...items);
364+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Forward all VS Code overloads unchanged; the public overloads above check callers.
365+
export function showWarningMessage(message: string, ...args: any[]): Thenable<string | MessageItem | undefined> {
366+
return window.showWarningMessage(message, ...args);
357367
}
358368

359369
export function showInputBox(options?: InputBoxOptions, token?: CancellationToken): Thenable<string | undefined> {
@@ -372,9 +382,10 @@ export function registerFileDecorationProvider(provider: FileDecorationProvider)
372382
return window.registerFileDecorationProvider(provider);
373383
}
374384

375-
export function onDidChangeWindowState(
376-
listener: (e: WindowState) => any,
377-
thisArgs?: any,
385+
/** Subscribes to window state changes, binding the listener to the optional receiver. */
386+
export function onDidChangeWindowState<TThis = void>(
387+
listener: (this: TThis, e: WindowState) => void,
388+
thisArgs?: TThis,
378389
disposables?: Disposable[],
379390
): Disposable {
380391
return window.onDidChangeWindowState(listener, thisArgs, disposables);

‎src/common/workspace.apis.ts‎

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-explicit-any */
21
import {
32
CancellationToken,
43
ConfigurationChangeEvent,
@@ -37,11 +36,13 @@ export function getConfiguration(section?: string, scope?: ConfigurationScope |
3736
return workspace.getConfiguration(section, scope);
3837
}
3938

40-
export function onDidChangeConfiguration(listener: (e: ConfigurationChangeEvent) => any): Disposable {
39+
/** Subscribes the listener to configuration changes; its return value is ignored. */
40+
export function onDidChangeConfiguration(listener: (e: ConfigurationChangeEvent) => void): Disposable {
4141
return workspace.onDidChangeConfiguration(listener);
4242
}
4343

44-
export function onDidChangeWorkspaceFolders(listener: (e: WorkspaceFoldersChangeEvent) => any): Disposable {
44+
/** Subscribes the listener to workspace folder changes; its return value is ignored. */
45+
export function onDidChangeWorkspaceFolders(listener: (e: WorkspaceFoldersChangeEvent) => void): Disposable {
4546
return workspace.onDidChangeWorkspaceFolders(listener);
4647
}
4748

@@ -67,49 +68,55 @@ export function createFileSystemWatcher(
6768
return workspace.createFileSystemWatcher(globPattern, ignoreCreateEvents, ignoreChangeEvents, ignoreDeleteEvents);
6869
}
6970

70-
export function onDidDeleteFiles(
71-
listener: (e: FileDeleteEvent) => any,
72-
thisArgs?: any,
71+
/** Subscribes to deleted files, binding the listener to the optional receiver. */
72+
export function onDidDeleteFiles<TThis = void>(
73+
listener: (this: TThis, e: FileDeleteEvent) => void,
74+
thisArgs?: TThis,
7375
disposables?: Disposable[],
7476
): Disposable {
7577
return workspace.onDidDeleteFiles(listener, thisArgs, disposables);
7678
}
7779

78-
export function onDidRenameFiles(
79-
listener: (e: FileRenameEvent) => any,
80-
thisArgs?: any,
80+
/** Subscribes to renamed files, binding the listener to the optional receiver. */
81+
export function onDidRenameFiles<TThis = void>(
82+
listener: (this: TThis, e: FileRenameEvent) => void,
83+
thisArgs?: TThis,
8184
disposables?: Disposable[],
8285
): Disposable {
8386
return workspace.onDidRenameFiles(listener, thisArgs, disposables);
8487
}
8588

86-
export function onDidOpenTextDocument(
87-
listener: (e: TextDocument) => any,
88-
thisArgs?: any,
89+
/** Subscribes to opened documents, binding the listener to the optional receiver. */
90+
export function onDidOpenTextDocument<TThis = void>(
91+
listener: (this: TThis, e: TextDocument) => void,
92+
thisArgs?: TThis,
8993
disposables?: Disposable[],
9094
): Disposable {
9195
return workspace.onDidOpenTextDocument(listener, thisArgs, disposables);
9296
}
9397

94-
export function onDidSaveTextDocument(
95-
listener: (e: TextDocument) => any,
96-
thisArgs?: any,
98+
/** Subscribes to saved documents, binding the listener to the optional receiver. */
99+
export function onDidSaveTextDocument<TThis = void>(
100+
listener: (this: TThis, e: TextDocument) => void,
101+
thisArgs?: TThis,
97102
disposables?: Disposable[],
98103
): Disposable {
99104
return workspace.onDidSaveTextDocument(listener, thisArgs, disposables);
100105
}
101106

102-
export function onDidCloseTextDocument(
103-
listener: (e: TextDocument) => any,
104-
thisArgs?: any,
107+
/** Subscribes to closed documents, binding the listener to the optional receiver. */
108+
export function onDidCloseTextDocument<TThis = void>(
109+
listener: (this: TThis, e: TextDocument) => void,
110+
thisArgs?: TThis,
105111
disposables?: Disposable[],
106112
): Disposable {
107113
return workspace.onDidCloseTextDocument(listener, thisArgs, disposables);
108114
}
109115

110-
export function onDidChangeTextDocument(
111-
listener: (e: TextDocumentChangeEvent) => any,
112-
thisArgs?: any,
116+
/** Subscribes to document changes, binding the listener to the optional receiver. */
117+
export function onDidChangeTextDocument<TThis = void>(
118+
listener: (this: TThis, e: TextDocumentChangeEvent) => void,
119+
thisArgs?: TThis,
113120
disposables?: Disposable[],
114121
): Disposable {
115122
return workspace.onDidChangeTextDocument(listener, thisArgs, disposables);

‎src/managers/builtin/pipUtils.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@ async function selectWorkspaceOrCommon(
214214
} else {
215215
return undefined;
216216
}
217-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
218-
} catch (ex: any) {
217+
} catch (ex) {
219218
if (ex === QuickInputButtons.Back) {
220219
return selectWorkspaceOrCommon(installableResult, common, showSkipOption, installed);
221220
}

‎src/managers/common/pickers.ts‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,25 @@ export async function selectFromCommonPackagesToInstall(
149149
handleItemButton(e.item.uri);
150150
},
151151
);
152-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
153-
} catch (ex: any) {
152+
} catch (ex) {
154153
if (ex === QuickInputButtons.Back) {
155154
throw ex;
156-
} else if (ex.button === EDIT_ARGUMENTS_BUTTON && ex.item) {
157-
const parts: PackageQuickPickItem[] = Array.isArray(ex.item) ? ex.item : [ex.item];
155+
} else if (
156+
typeof ex === 'object' &&
157+
ex !== null &&
158+
'button' in ex &&
159+
ex.button === EDIT_ARGUMENTS_BUTTON &&
160+
'item' in ex &&
161+
ex.item
162+
) {
163+
const selection: readonly unknown[] = Array.isArray(ex.item) ? ex.item : [ex.item];
164+
const parts = selection.map((part) => {
165+
const item = items.find((candidate) => candidate === part);
166+
if (!item) {
167+
throw ex;
168+
}
169+
return item;
170+
});
158171
selected = [
159172
{
160173
id: PackageManagement.enterPackageNames,
@@ -163,6 +176,8 @@ export async function selectFromCommonPackagesToInstall(
163176
},
164177
...parts,
165178
];
179+
} else {
180+
throw ex;
166181
}
167182
}
168183

‎src/managers/conda/condaUtils.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,8 +1313,7 @@ async function selectCommonPackagesOrSkip(
13131313
traceInfo('Package Installer: user selected skip package installation');
13141314
return undefined;
13151315
}
1316-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1317-
} catch (ex: any) {
1316+
} catch (ex) {
13181317
if (ex === QuickInputButtons.Back) {
13191318
return selectCommonPackagesOrSkip(common, installed, showSkipOption);
13201319
}

0 commit comments

Comments
 (0)