Skip to content
This repository was archived by the owner on Oct 23, 2025. It is now read-only.

Commit ad44e33

Browse files
authored
fix as-any linting warnings (#891)
fixes microsoft/vscode-python-environments#881
1 parent a0b4c74 commit ad44e33

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

.github/instructions/generic.instructions.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ Provide project context and coding guidelines that AI should follow when generat
3030
## Documentation
3131

3232
- Add clear docstrings to public functions, describing their purpose, parameters, and behavior.
33+
34+
## Learnings
35+
36+
- Avoid using 'any' types in TypeScript; import proper types from VS Code API and use specific interfaces for mocks and test objects (1)

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ export default [{
3535
eqeqeq: "warn",
3636
"no-throw-literal": "warn",
3737
semi: "warn",
38-
"@typescript-eslint/no-explicit-any": "warn",
38+
"@typescript-eslint/no-explicit-any": "error",
3939
},
4040
}];

src/test/features/terminalEnvVarInjectorBasic.unit.test.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
import * as sinon from 'sinon';
55
import * as typeMoq from 'typemoq';
6-
import { GlobalEnvironmentVariableCollection, workspace } from 'vscode';
6+
import { Disposable, GlobalEnvironmentVariableCollection, workspace, WorkspaceFolder } from 'vscode';
7+
import { DidChangeEnvironmentVariablesEventArgs } from '../../api';
78
import { EnvVarManager } from '../../features/execution/envVariableManager';
89
import { TerminalEnvVarInjector } from '../../features/terminal/terminalEnvVarInjector';
910

@@ -18,8 +19,7 @@ suite('TerminalEnvVarInjector Basic Tests', () => {
1819
let envVarManager: typeMoq.IMock<EnvVarManager>;
1920
let injector: TerminalEnvVarInjector;
2021
let mockScopedCollection: MockScopedCollection;
21-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
22-
let workspaceFoldersStub: any;
22+
let workspaceFoldersStub: WorkspaceFolder[];
2323

2424
setup(() => {
2525
envVarCollection = typeMoq.Mock.ofType<GlobalEnvironmentVariableCollection>();
@@ -40,19 +40,25 @@ suite('TerminalEnvVarInjector Basic Tests', () => {
4040
};
4141

4242
// Setup environment variable collection to return scoped collection
43-
envVarCollection.setup((x) => x.getScoped(typeMoq.It.isAny())).returns(() => mockScopedCollection as any);
43+
envVarCollection.setup((x) => x.getScoped(typeMoq.It.isAny())).returns(() => mockScopedCollection as never);
4444
envVarCollection.setup((x) => x.clear()).returns(() => {});
4545

4646
// Setup minimal mocks for event subscriptions
4747
envVarManager
4848
.setup((m) => m.onDidChangeEnvironmentVariables)
49-
.returns(
50-
() =>
49+
.returns(() => {
50+
// Return a mock Event function that returns a Disposable when called
51+
const mockEvent = (_listener: (e: DidChangeEnvironmentVariablesEventArgs) => void) =>
5152
({
5253
dispose: () => {},
53-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
54-
} as any),
55-
);
54+
} as Disposable);
55+
return mockEvent;
56+
});
57+
58+
// Mock workspace.onDidChangeConfiguration to return a Disposable
59+
sinon.stub(workspace, 'onDidChangeConfiguration').returns({
60+
dispose: () => {},
61+
} as Disposable);
5662
});
5763

5864
teardown(() => {
@@ -85,12 +91,21 @@ suite('TerminalEnvVarInjector Basic Tests', () => {
8591
envVarManager.reset();
8692
envVarManager
8793
.setup((m) => m.onDidChangeEnvironmentVariables)
88-
.returns((_handler) => {
94+
.returns(() => {
8995
eventHandlerRegistered = true;
90-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
91-
return { dispose: () => {} } as any;
96+
// Return a mock Event function that returns a Disposable when called
97+
const mockEvent = (_listener: (e: DidChangeEnvironmentVariablesEventArgs) => void) =>
98+
({
99+
dispose: () => {},
100+
} as Disposable);
101+
return mockEvent;
92102
});
93103

104+
// Mock workspace.onDidChangeConfiguration to return a Disposable
105+
sinon.stub(workspace, 'onDidChangeConfiguration').returns({
106+
dispose: () => {},
107+
} as Disposable);
108+
94109
// Act
95110
injector = new TerminalEnvVarInjector(envVarCollection.object, envVarManager.object);
96111

0 commit comments

Comments
 (0)