diff --git a/.github/instructions/generic.instructions.md b/.github/instructions/generic.instructions.md index 3f43f207..5ac0cc0d 100644 --- a/.github/instructions/generic.instructions.md +++ b/.github/instructions/generic.instructions.md @@ -30,3 +30,7 @@ Provide project context and coding guidelines that AI should follow when generat ## Documentation - Add clear docstrings to public functions, describing their purpose, parameters, and behavior. + +## Learnings + +- Avoid using 'any' types in TypeScript; import proper types from VS Code API and use specific interfaces for mocks and test objects (1) diff --git a/eslint.config.mjs b/eslint.config.mjs index 60ebcf3a..cfa27fdf 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -35,6 +35,6 @@ export default [{ eqeqeq: "warn", "no-throw-literal": "warn", semi: "warn", - "@typescript-eslint/no-explicit-any": "warn", + "@typescript-eslint/no-explicit-any": "error", }, }]; \ No newline at end of file diff --git a/src/test/features/terminalEnvVarInjectorBasic.unit.test.ts b/src/test/features/terminalEnvVarInjectorBasic.unit.test.ts index 4b009e99..5e7ffe54 100644 --- a/src/test/features/terminalEnvVarInjectorBasic.unit.test.ts +++ b/src/test/features/terminalEnvVarInjectorBasic.unit.test.ts @@ -3,7 +3,8 @@ import * as sinon from 'sinon'; import * as typeMoq from 'typemoq'; -import { GlobalEnvironmentVariableCollection, workspace } from 'vscode'; +import { Disposable, GlobalEnvironmentVariableCollection, workspace, WorkspaceFolder } from 'vscode'; +import { DidChangeEnvironmentVariablesEventArgs } from '../../api'; import { EnvVarManager } from '../../features/execution/envVariableManager'; import { TerminalEnvVarInjector } from '../../features/terminal/terminalEnvVarInjector'; @@ -18,8 +19,7 @@ suite('TerminalEnvVarInjector Basic Tests', () => { let envVarManager: typeMoq.IMock; let injector: TerminalEnvVarInjector; let mockScopedCollection: MockScopedCollection; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - let workspaceFoldersStub: any; + let workspaceFoldersStub: WorkspaceFolder[]; setup(() => { envVarCollection = typeMoq.Mock.ofType(); @@ -40,19 +40,25 @@ suite('TerminalEnvVarInjector Basic Tests', () => { }; // Setup environment variable collection to return scoped collection - envVarCollection.setup((x) => x.getScoped(typeMoq.It.isAny())).returns(() => mockScopedCollection as any); + envVarCollection.setup((x) => x.getScoped(typeMoq.It.isAny())).returns(() => mockScopedCollection as never); envVarCollection.setup((x) => x.clear()).returns(() => {}); // Setup minimal mocks for event subscriptions envVarManager .setup((m) => m.onDidChangeEnvironmentVariables) - .returns( - () => + .returns(() => { + // Return a mock Event function that returns a Disposable when called + const mockEvent = (_listener: (e: DidChangeEnvironmentVariablesEventArgs) => void) => ({ dispose: () => {}, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } as any), - ); + } as Disposable); + return mockEvent; + }); + + // Mock workspace.onDidChangeConfiguration to return a Disposable + sinon.stub(workspace, 'onDidChangeConfiguration').returns({ + dispose: () => {}, + } as Disposable); }); teardown(() => { @@ -85,12 +91,21 @@ suite('TerminalEnvVarInjector Basic Tests', () => { envVarManager.reset(); envVarManager .setup((m) => m.onDidChangeEnvironmentVariables) - .returns((_handler) => { + .returns(() => { eventHandlerRegistered = true; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return { dispose: () => {} } as any; + // Return a mock Event function that returns a Disposable when called + const mockEvent = (_listener: (e: DidChangeEnvironmentVariablesEventArgs) => void) => + ({ + dispose: () => {}, + } as Disposable); + return mockEvent; }); + // Mock workspace.onDidChangeConfiguration to return a Disposable + sinon.stub(workspace, 'onDidChangeConfiguration').returns({ + dispose: () => {}, + } as Disposable); + // Act injector = new TerminalEnvVarInjector(envVarCollection.object, envVarManager.object);