From 2bb9d27b381aa156ce43149a33ec86ffab33a188 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Mon, 21 Dec 2020 17:02:37 -0800 Subject: [PATCH] Turn `no-explicit-any` into an eslint error (#15032) --- .eslintrc | 1 + .vscode/settings.json | 10 ++++++++++ src/client/jupyter/types.ts | 2 ++ .../locators/services/cacheableLocatorService.ts | 4 ++-- src/client/pythonEnvironments/info/index.ts | 1 + src/test/languageServers/jedi/lspSetup.ts | 1 + .../locators/cacheableLocatorService.unit.test.ts | 11 ++++++++--- .../discovery/locators/condaHelper.unit.test.ts | 1 + .../discovery/locators/condaService.unit.test.ts | 2 ++ .../locators/hasProviderFactory.unit.test.ts | 3 +++ .../locators/interpreterWatcherBuilder.unit.test.ts | 2 ++ .../discovery/locators/pipEnvService.unit.test.ts | 2 ++ .../locators/windowsRegistryService.unit.test.ts | 3 +++ .../locators/windowsStoreInterpreter.unit.test.ts | 1 + .../locators/workspaceVirtualEnvService.unit.test.ts | 2 ++ .../workspaceVirtualEnvWatcherService.unit.test.ts | 7 +++++-- 16 files changed, 46 insertions(+), 7 deletions(-) diff --git a/.eslintrc b/.eslintrc index 0a40f0738760..3779c6bd7de1 100644 --- a/.eslintrc +++ b/.eslintrc @@ -28,6 +28,7 @@ "no-empty-function": "off", "@typescript-eslint/no-empty-function": ["error"], "@typescript-eslint/no-empty-interface": "off", + "@typescript-eslint/no-explicit-any": "error", "@typescript-eslint/no-non-null-assertion": "off", "no-unused-vars": "off", "@typescript-eslint/no-unused-vars": "error", diff --git a/.vscode/settings.json b/.vscode/settings.json index 87f4fe0c61e1..de42fdbe8eb1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -25,9 +25,19 @@ "editor.formatOnSave": true }, "[typescript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.formatOnSave": true }, "[javascript]": { + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true + }, + "[JSON]": { + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true + }, + "[YAML]": { + "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.formatOnSave": true }, "typescript.tsdk": "./node_modules/typescript/lib", // we want to use the TS server from our node_modules folder to control its version diff --git a/src/client/jupyter/types.ts b/src/client/jupyter/types.ts index a60c39044411..ae9695cf8b7d 100644 --- a/src/client/jupyter/types.ts +++ b/src/client/jupyter/types.ts @@ -9,6 +9,7 @@ export interface IJupyterServerUri { baseUrl: string; token: string; + // eslint-disable-next-line @typescript-eslint/no-explicit-any authorizationHeader: any; // JSON object for authorization header. expiration?: Date; // Date/time when header expires and should be refreshed. displayName: string; @@ -42,4 +43,5 @@ export enum ColumnType { Bool = 'bool', } +// eslint-disable-next-line @typescript-eslint/no-explicit-any export type IRowsResponse = any[]; diff --git a/src/client/pythonEnvironments/discovery/locators/services/cacheableLocatorService.ts b/src/client/pythonEnvironments/discovery/locators/services/cacheableLocatorService.ts index 3b1e20ab525e..566f5aaf3e55 100644 --- a/src/client/pythonEnvironments/discovery/locators/services/cacheableLocatorService.ts +++ b/src/client/pythonEnvironments/discovery/locators/services/cacheableLocatorService.ts @@ -187,9 +187,9 @@ export abstract class CacheableLocatorService implements IInterpreterLocatorServ const cacheKey = this.getCacheKey(resource); const persistentFactory = this.serviceContainer.get(IPersistentStateFactory); if (this.cachePerWorkspace) { - return persistentFactory.createWorkspacePersistentState(cacheKey, undefined as any); + return persistentFactory.createWorkspacePersistentState(cacheKey, undefined); } - return persistentFactory.createGlobalPersistentState(cacheKey, undefined as any); + return persistentFactory.createGlobalPersistentState(cacheKey, undefined); } protected getCachedInterpreters(resource?: Uri): PythonEnvironment[] | undefined { diff --git a/src/client/pythonEnvironments/info/index.ts b/src/client/pythonEnvironments/info/index.ts index 5b14ed8e05d8..7d4704f77337 100644 --- a/src/client/pythonEnvironments/info/index.ts +++ b/src/client/pythonEnvironments/info/index.ts @@ -173,6 +173,7 @@ export function updateEnvironment(environment: PartialPythonEnvironment, other: ]; props.forEach((prop) => { if (!environment[prop] && other[prop]) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any (environment as any)[prop] = other[prop]; } }); diff --git a/src/test/languageServers/jedi/lspSetup.ts b/src/test/languageServers/jedi/lspSetup.ts index b8c03b66b119..451a66baa8ea 100644 --- a/src/test/languageServers/jedi/lspSetup.ts +++ b/src/test/languageServers/jedi/lspSetup.ts @@ -17,6 +17,7 @@ const settingsJsonPath = path.join(__dirname, '..', '..', '..', '..', 'src', 'te const settingsJsonPromise = import('../../.vscode/settings.json'); settingsJsonPromise.then((settingsJson) => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any (settingsJson)['python.experiments.optInto'] = [JediLSP.experiment]; return fs.writeFile(settingsJsonPath, JSON.stringify(settingsJson, undefined, ' ')); }); diff --git a/src/test/pythonEnvironments/discovery/locators/cacheableLocatorService.unit.test.ts b/src/test/pythonEnvironments/discovery/locators/cacheableLocatorService.unit.test.ts index 406943d17933..fc57fba65c4f 100644 --- a/src/test/pythonEnvironments/discovery/locators/cacheableLocatorService.unit.test.ts +++ b/src/test/pythonEnvironments/discovery/locators/cacheableLocatorService.unit.test.ts @@ -76,6 +76,7 @@ suite('Interpreters - Cacheable Locator Service', () => { }); test('Interpreters must be retrieved once, then cached', async () => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any const expectedInterpreters = [1, 2] as any; const mockedLocatorForVerification = mock(MockLocator); const locator = new (class extends Locator { @@ -113,9 +114,9 @@ suite('Interpreters - Cacheable Locator Service', () => { class Watcher implements IInterpreterWatcher { // eslint-disable-next-line class-methods-use-this public onDidCreate( - // eslint-disable-next-line @typescript-eslint/no-unused-vars + // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any _listener: (e: Resource) => any, - // eslint-disable-next-line @typescript-eslint/no-unused-vars + // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any _thisArgs?: any, // eslint-disable-next-line @typescript-eslint/no-unused-vars _disposables?: Disposable[], @@ -138,14 +139,17 @@ suite('Interpreters - Cacheable Locator Service', () => { }); test('Ensure cache is cleared when watcher event fires', async () => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any const expectedInterpreters = [1, 2] as any; const mockedLocatorForVerification = mock(MockLocator); class Watcher implements IInterpreterWatcher { + // eslint-disable-next-line @typescript-eslint/no-explicit-any private listner?: (e: Resource) => any; public onDidCreate( + // eslint-disable-next-line @typescript-eslint/no-explicit-any listener: (e: Resource) => any, - // eslint-disable-next-line @typescript-eslint/no-unused-vars + // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any _thisArgs?: any, // eslint-disable-next-line @typescript-eslint/no-unused-vars _disposables?: Disposable[], @@ -213,6 +217,7 @@ suite('Interpreters - Cacheable Locator Service', () => { locatingEventRaised = true; }); + // eslint-disable-next-line @typescript-eslint/no-explicit-any when(mockedLocatorForVerification.getInterpretersImplementation()).thenResolve([1, 2] as any); when(mockedLocatorForVerification.getCacheKey()).thenReturn('xyz'); when(mockedLocatorForVerification.getCachedInterpreters()).thenResolve(); diff --git a/src/test/pythonEnvironments/discovery/locators/condaHelper.unit.test.ts b/src/test/pythonEnvironments/discovery/locators/condaHelper.unit.test.ts index 30abb00cbfa4..8c5f6e08cd64 100644 --- a/src/test/pythonEnvironments/discovery/locators/condaHelper.unit.test.ts +++ b/src/test/pythonEnvironments/discovery/locators/condaHelper.unit.test.ts @@ -190,6 +190,7 @@ suite('Conda binary is located correctly', () => { return Object.keys(getFile(filePath)); }); + // eslint-disable-next-line @typescript-eslint/no-explicit-any sinon.stub(fsapi, 'readFile' as any).callsFake(async (filePath: string | Buffer | number, encoding: string) => { if (typeof filePath !== 'string') { throw new Error(`expected filePath to be string, got ${typeof filePath}`); diff --git a/src/test/pythonEnvironments/discovery/locators/condaService.unit.test.ts b/src/test/pythonEnvironments/discovery/locators/condaService.unit.test.ts index f209e6387bff..40647cef9f5a 100644 --- a/src/test/pythonEnvironments/discovery/locators/condaService.unit.test.ts +++ b/src/test/pythonEnvironments/discovery/locators/condaService.unit.test.ts @@ -69,6 +69,7 @@ suite('Interpreters Conda Service', () => { config = TypeMoq.Mock.ofType(); settings = TypeMoq.Mock.ofType(); procServiceFactory = TypeMoq.Mock.ofType(); + // eslint-disable-next-line @typescript-eslint/no-explicit-any processService.setup((x: any) => x.then).returns(() => undefined); procServiceFactory .setup((p) => p.create(TypeMoq.It.isAny())) @@ -133,6 +134,7 @@ suite('Interpreters Conda Service', () => { ); }); + // eslint-disable-next-line @typescript-eslint/no-explicit-any function resetMockState(data: any) { mockState = new MockState(data); } diff --git a/src/test/pythonEnvironments/discovery/locators/hasProviderFactory.unit.test.ts b/src/test/pythonEnvironments/discovery/locators/hasProviderFactory.unit.test.ts index 6de7690d1a5b..d3a0cdb11474 100644 --- a/src/test/pythonEnvironments/discovery/locators/hasProviderFactory.unit.test.ts +++ b/src/test/pythonEnvironments/discovery/locators/hasProviderFactory.unit.test.ts @@ -26,6 +26,7 @@ suite('Interpretersx - Interpreter Hash Provider Factory', () => { windowsStoreInterpreter = mock(WindowsStoreInterpreter); standardHashProvider = mock(InterpreterHashProvider); const windowsStoreInstance = instance(windowsStoreInterpreter); + // eslint-disable-next-line @typescript-eslint/no-explicit-any (windowsStoreInstance as any).then = undefined; factory = new InterpeterHashProviderFactory( instance(configService), @@ -55,6 +56,7 @@ suite('Interpretersx - Interpreter Hash Provider Factory', () => { test('When provided resource resolves to a python path that is not a window store interpreter return standard hash provider', async () => { const pythonPath = 'NonWindowsInterpreterPath'; const resource = Uri.file('1'); + // eslint-disable-next-line @typescript-eslint/no-explicit-any when(configService.getSettings(resource)).thenReturn({ pythonPath } as any); when(windowsStoreInterpreter.isWindowsStoreInterpreter(pythonPath)).thenReturn(Promise.resolve(false)); @@ -66,6 +68,7 @@ suite('Interpretersx - Interpreter Hash Provider Factory', () => { test('When provided resource resolves to a python path that is a windows store interpreter return windows store hash provider', async () => { const pythonPath = 'NonWindowsInterpreterPath'; const resource = Uri.file('1'); + // eslint-disable-next-line @typescript-eslint/no-explicit-any when(configService.getSettings(resource)).thenReturn({ pythonPath } as any); when(windowsStoreInterpreter.isWindowsStoreInterpreter(pythonPath)).thenReturn(Promise.resolve(true)); diff --git a/src/test/pythonEnvironments/discovery/locators/interpreterWatcherBuilder.unit.test.ts b/src/test/pythonEnvironments/discovery/locators/interpreterWatcherBuilder.unit.test.ts index 055f3249adea..6bb904ed7fd8 100644 --- a/src/test/pythonEnvironments/discovery/locators/interpreterWatcherBuilder.unit.test.ts +++ b/src/test/pythonEnvironments/discovery/locators/interpreterWatcherBuilder.unit.test.ts @@ -19,6 +19,7 @@ suite('Interpreters - Watcher Builder', () => { when(workspaceService.getWorkspaceFolder(anything())).thenReturn(); when(serviceContainer.get(IInterpreterWatcher, WORKSPACE_VIRTUAL_ENV_SERVICE)).thenReturn( + // eslint-disable-next-line @typescript-eslint/no-explicit-any (watcher as any) as IInterpreterWatcher, ); @@ -34,6 +35,7 @@ suite('Interpreters - Watcher Builder', () => { when(workspaceService.getWorkspaceFolder(anything())).thenReturn(); when(serviceContainer.get(IInterpreterWatcher, WORKSPACE_VIRTUAL_ENV_SERVICE)).thenReturn( + // eslint-disable-next-line @typescript-eslint/no-explicit-any (watcher as any) as IInterpreterWatcher, ); diff --git a/src/test/pythonEnvironments/discovery/locators/pipEnvService.unit.test.ts b/src/test/pythonEnvironments/discovery/locators/pipEnvService.unit.test.ts index 778902bef7ca..872bff8b720a 100644 --- a/src/test/pythonEnvironments/discovery/locators/pipEnvService.unit.test.ts +++ b/src/test/pythonEnvironments/discovery/locators/pipEnvService.unit.test.ts @@ -72,11 +72,13 @@ suite('Interpreters - PipEnv', () => { procServiceFactory = TypeMoq.Mock.ofType(); platformService = TypeMoq.Mock.ofType(); pipEnvServiceHelper = mock(PipEnvServiceHelper); + // eslint-disable-next-line @typescript-eslint/no-explicit-any processService.setup((x: any) => x.then).returns(() => undefined); procServiceFactory .setup((p) => p.create(TypeMoq.It.isAny())) .returns(() => Promise.resolve(processService.object)); + // eslint-disable-next-line @typescript-eslint/no-explicit-any const persistentState = TypeMoq.Mock.ofType>(); persistentStateFactory .setup((p) => p.createGlobalPersistentState(TypeMoq.It.isAny(), TypeMoq.It.isAny())) diff --git a/src/test/pythonEnvironments/discovery/locators/windowsRegistryService.unit.test.ts b/src/test/pythonEnvironments/discovery/locators/windowsRegistryService.unit.test.ts index d2e73df96e33..0b721628eb31 100644 --- a/src/test/pythonEnvironments/discovery/locators/windowsRegistryService.unit.test.ts +++ b/src/test/pythonEnvironments/discovery/locators/windowsRegistryService.unit.test.ts @@ -50,6 +50,7 @@ suite('Interpreters from Windows Registry (unit)', () => { interpreterHelper .setup((h) => h.getInterpreterInformation(TypeMoq.It.isAny())) + // eslint-disable-next-line @typescript-eslint/no-explicit-any .returns(() => Promise.resolve({} as any)); stateFactory .setup((s) => s.createGlobalPersistentState(TypeMoq.It.isAny(), TypeMoq.It.isAny())) @@ -736,6 +737,7 @@ suite('Interpreters from Windows Registry (unit)', () => { hive: RegistryHive.HKCU, arch: Architecture.x86, + // eslint-disable-next-line @typescript-eslint/no-explicit-any value: undefined, }, @@ -955,6 +957,7 @@ suite('Interpreters from Windows Registry (unit)', () => { hive: RegistryHive.HKCU, arch: Architecture.x86, + // eslint-disable-next-line @typescript-eslint/no-explicit-any value: undefined, }, diff --git a/src/test/pythonEnvironments/discovery/locators/windowsStoreInterpreter.unit.test.ts b/src/test/pythonEnvironments/discovery/locators/windowsStoreInterpreter.unit.test.ts index 65017c156b13..488bdda27037 100644 --- a/src/test/pythonEnvironments/discovery/locators/windowsStoreInterpreter.unit.test.ts +++ b/src/test/pythonEnvironments/discovery/locators/windowsStoreInterpreter.unit.test.ts @@ -155,6 +155,7 @@ suite('Interpreters - Windows Store Interpreter', () => { const key = `WINDOWS_STORE_INTERPRETER_HASH_${pythonPath}`; const pythonService = mock(); const pythonServiceInstance = instance(pythonService); + // eslint-disable-next-line @typescript-eslint/no-explicit-any (pythonServiceInstance as any).then = undefined; const oneHour = 60 * 60 * 1000; diff --git a/src/test/pythonEnvironments/discovery/locators/workspaceVirtualEnvService.unit.test.ts b/src/test/pythonEnvironments/discovery/locators/workspaceVirtualEnvService.unit.test.ts index 83ec373585d1..bd15e421b68d 100644 --- a/src/test/pythonEnvironments/discovery/locators/workspaceVirtualEnvService.unit.test.ts +++ b/src/test/pythonEnvironments/discovery/locators/workspaceVirtualEnvService.unit.test.ts @@ -19,8 +19,10 @@ suite('Interpreters - Workspace VirtualEnv Service', () => { public async getInterpreterWatchers(resource: Uri | undefined): Promise { return super.getInterpreterWatchers(resource); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any })(undefined as any, instance(serviceContainer), instance(builder)); + // eslint-disable-next-line @typescript-eslint/no-explicit-any const watchers = 1 as any; when(builder.getWorkspaceVirtualEnvInterpreterWatcher(anything())).thenResolve(watchers); diff --git a/src/test/pythonEnvironments/discovery/locators/workspaceVirtualEnvWatcherService.unit.test.ts b/src/test/pythonEnvironments/discovery/locators/workspaceVirtualEnvWatcherService.unit.test.ts index a78006b7c89e..b14ded03ec50 100644 --- a/src/test/pythonEnvironments/discovery/locators/workspaceVirtualEnvWatcherService.unit.test.ts +++ b/src/test/pythonEnvironments/discovery/locators/workspaceVirtualEnvWatcherService.unit.test.ts @@ -53,7 +53,7 @@ suite('Interpreters - Workspace VirtualEnv Watcher Service', () => { when(platformService.isMac).thenReturn(os === OSType.OSX); class FSWatcher { - // eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars + // eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any public onDidCreate(_listener: (e: Uri) => any, _thisArgs?: any, _disposables?: Disposable[]): Disposable { return { dispose: noop }; } @@ -68,6 +68,7 @@ suite('Interpreters - Workspace VirtualEnv Watcher Service', () => { const fsWatcher = mock(FSWatcher); when(workspaceService.createFileSystemWatcher(anything())).thenReturn( + // eslint-disable-next-line @typescript-eslint/no-explicit-any instance((fsWatcher as any) as FileSystemWatcher), ); @@ -108,9 +109,10 @@ suite('Interpreters - Workspace VirtualEnv Watcher Service', () => { when(platformService.isMac).thenReturn(os === OSType.OSX); class FSWatcher { + // eslint-disable-next-line @typescript-eslint/no-explicit-any private listener?: (e: Uri) => any; - // eslint-disable-next-line @typescript-eslint/no-unused-vars + // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any public onDidCreate(listener: (e: Uri) => any, _thisArgs?: any, _disposables?: Disposable[]): Disposable { this.listener = listener; return { dispose: noop }; @@ -122,6 +124,7 @@ suite('Interpreters - Workspace VirtualEnv Watcher Service', () => { } const fsWatcher = new FSWatcher(); when(workspaceService.getWorkspaceFolder(anything())).thenReturn(undefined); + // eslint-disable-next-line @typescript-eslint/no-explicit-any when(workspaceService.createFileSystemWatcher(anything())).thenReturn((fsWatcher as any) as FileSystemWatcher); await watcher.register(undefined); let invoked = false;