diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 3535797eb92c..000000000000 --- a/.eslintrc +++ /dev/null @@ -1,107 +0,0 @@ -{ - "env": { - "node": true, - "es6": true, - "mocha": true - }, - "parser": "@typescript-eslint/parser", - "plugins": [ - "@typescript-eslint", - "no-only-tests" - ], - "extends": [ - "plugin:@typescript-eslint/recommended", - "plugin:import/errors", - "plugin:import/warnings", - "plugin:import/typescript", - "prettier" - ], - "rules": { - // Overriding ESLint rules with Typescript-specific ones - "@typescript-eslint/ban-ts-comment": [ - "error", - { - "ts-ignore": "allow-with-description" - } - ], - "@typescript-eslint/explicit-module-boundary-types": "error", - "no-bitwise": "off", - "no-dupe-class-members": "off", - "@typescript-eslint/no-dupe-class-members": "error", - "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", - { - "args": "after-used", - "argsIgnorePattern": "^_" - } - ], - "no-use-before-define": "off", - "@typescript-eslint/no-use-before-define": [ - "error", - { - "functions": false - } - ], - "no-useless-constructor": "off", - "@typescript-eslint/no-useless-constructor": "error", - "@typescript-eslint/no-var-requires": "off", - - // Other rules - "class-methods-use-this": ["error", { "exceptMethods": ["dispose"] }], - "func-names": "off", - "import/extensions": "off", - "import/namespace": "off", - "import/no-extraneous-dependencies": "off", - "import/no-unresolved": [ - "error", - { - "ignore": ["monaco-editor", "vscode"] - } - ], - "import/prefer-default-export": "off", - "linebreak-style": "off", - "no-await-in-loop": "off", - "no-console": "off", - "no-control-regex": "off", - "no-extend-native": "off", - "no-multi-str": "off", - "no-shadow": "off", - "no-param-reassign": "off", - "no-prototype-builtins": "off", - "no-restricted-syntax": [ - "error", - { - "selector": "ForInStatement", - "message": "for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array." - }, - { - "selector": "LabeledStatement", - "message": "Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand." - }, - { - "selector": "WithStatement", - "message": "`with` is disallowed in strict mode because it makes code impossible to predict and optimize." - } - ], - "no-template-curly-in-string": "off", - "no-underscore-dangle": "off", - "no-useless-escape": "off", - "no-void": [ - "error", - { - "allowAsStatement": true - } - ], - "operator-assignment": "off", - "strict": "off", - "no-only-tests/no-only-tests": ["error", { "block": ["test", "suite"], "focus": ["only"] }], - "prefer-const": "off", - "import/no-named-as-default-member": "off" - } -} diff --git a/build/webpack/webpack.extension.browser.config.js b/build/webpack/webpack.extension.browser.config.js index 909cceaf1bea..f90d207a3d92 100644 --- a/build/webpack/webpack.extension.browser.config.js +++ b/build/webpack/webpack.extension.browser.config.js @@ -13,7 +13,7 @@ const packageRoot = path.resolve(__dirname, '..', '..'); const outDir = path.resolve(packageRoot, 'dist'); /** @type {(env: any, argv: { mode: 'production' | 'development' | 'none' }) => import('webpack').Configuration} */ -// eslint-disable-next-line @typescript-eslint/no-unused-vars +// eslint-disable-next-line no-unused-vars const nodeConfig = (_, { mode }) => ({ context: packageRoot, entry: { diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 000000000000..297a0ba7ee68 --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,173 @@ +/** + * ESLint Configuration for VS Code Python Extension + * This file configures linting rules for the TypeScript/JavaScript codebase. + * It uses the new flat config format introduced in ESLint 8.21.0 + */ + +// Import essential ESLint plugins and configurations +import tseslint from '@typescript-eslint/eslint-plugin'; +import tsParser from '@typescript-eslint/parser'; +import noOnlyTests from 'eslint-plugin-no-only-tests'; +import prettier from 'eslint-config-prettier'; +import importPlugin from 'eslint-plugin-import'; +import js from '@eslint/js'; + +export default [ + { + ignores: ['**/node_modules/**', '**/out/**'], + }, + // Base configuration for all files + { + ignores: ['**/node_modules/**', '**/out/**'], + linterOptions: { + reportUnusedDisableDirectives: 'off', + }, + rules: { + ...js.configs.recommended.rules, + 'no-undef': 'off', + }, + }, + // TypeScript-specific configuration + { + files: ['**/*.ts', '**/*.tsx', 'src', 'pythonExtensionApi/src'], + languageOptions: { + parser: tsParser, + parserOptions: { + ecmaVersion: 'latest', + sourceType: 'module', + }, + globals: { + ...(js.configs.recommended.languageOptions?.globals || {}), + mocha: true, + require: 'readonly', + process: 'readonly', + exports: 'readonly', + module: 'readonly', + __dirname: 'readonly', + __filename: 'readonly', + setTimeout: 'readonly', + setInterval: 'readonly', + clearTimeout: 'readonly', + clearInterval: 'readonly', + }, + }, + plugins: { + '@typescript-eslint': tseslint, + 'no-only-tests': noOnlyTests, + import: importPlugin, + prettier: prettier, + }, + settings: { + 'import/resolver': { + node: { + extensions: ['.js', '.ts'], + }, + }, + }, + rules: { + // Base configurations + ...tseslint.configs.recommended.rules, + ...prettier.rules, + + // TypeScript-specific rules + '@typescript-eslint/ban-ts-comment': [ + 'error', + { + 'ts-ignore': 'allow-with-description', + }, + ], + '@typescript-eslint/ban-types': 'off', + '@typescript-eslint/explicit-module-boundary-types': 'off', + '@typescript-eslint/no-empty-interface': 'off', + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-namespace': 'off', + '@typescript-eslint/no-non-null-assertion': 'off', + '@typescript-eslint/no-loss-of-precision': 'off', + '@typescript-eslint/no-unused-vars': [ + 'warn', + { + varsIgnorePattern: '^_', + argsIgnorePattern: '^_', + }, + ], + '@typescript-eslint/no-var-requires': 'off', + '@typescript-eslint/no-use-before-define': [ + 'error', + { + functions: false, + }, + ], + + // Import rules + 'import/extensions': 'off', + 'import/namespace': 'off', + 'import/no-extraneous-dependencies': 'off', + 'import/no-unresolved': 'off', + 'import/prefer-default-export': 'off', + + // Testing rules + 'no-only-tests/no-only-tests': [ + 'error', + { + block: ['test', 'suite'], + focus: ['only'], + }, + ], + + // Code style rules + 'linebreak-style': 'off', + 'no-bitwise': 'off', + 'no-console': 'off', + 'no-underscore-dangle': 'off', + 'operator-assignment': 'off', + 'func-names': 'off', + + // Error handling and control flow + 'no-empty': ['error', { allowEmptyCatch: true }], + 'no-async-promise-executor': 'off', + 'no-await-in-loop': 'off', + 'no-unreachable': 'off', + 'no-void': 'off', + + // Duplicates and overrides (TypeScript handles these) + 'no-dupe-class-members': 'off', + 'no-redeclare': 'off', + 'no-undef': 'off', + + // Miscellaneous rules + 'no-control-regex': 'off', + 'no-extend-native': 'off', + 'no-inner-declarations': 'off', + 'no-multi-str': 'off', + 'no-param-reassign': 'off', + 'no-prototype-builtins': 'off', + 'no-empty-function': 'off', + 'no-template-curly-in-string': 'off', + 'no-useless-escape': 'off', + 'no-extra-parentheses': 'off', + 'no-extra-paren': 'off', + '@typescript-eslint/no-extra-parens': 'off', + strict: 'off', + + // Restricted syntax + 'no-restricted-syntax': [ + 'error', + { + selector: 'ForInStatement', + message: + 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.', + }, + { + selector: 'LabeledStatement', + message: + 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.', + }, + { + selector: 'WithStatement', + message: + '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.', + }, + ], + }, + }, +]; diff --git a/package.json b/package.json index 5c7f91de335a..e29c5dfc43d9 100644 --- a/package.json +++ b/package.json @@ -1501,8 +1501,8 @@ "testSmoke": "cross-env INSTALL_JUPYTER_EXTENSION=true \"node ./out/test/smokeTest.js\"", "testInsiders": "cross-env VSC_PYTHON_CI_TEST_VSC_CHANNEL=insiders INSTALL_PYLANCE_EXTENSION=true TEST_FILES_SUFFIX=insiders.test CODE_TESTS_WORKSPACE=src/testMultiRootWkspc/smokeTests \"node ./out/test/standardTest.js\"", "lint-staged": "node gulpfile.js", - "lint": "eslint --ext .ts,.js src build pythonExtensionApi", - "lint-fix": "eslint --fix --ext .ts,.js src build pythonExtensionApi gulpfile.js", + "lint": "eslint src build pythonExtensionApi", + "lint-fix": "eslint --fix src build pythonExtensionApi gulpfile.js", "format-check": "prettier --check 'src/**/*.ts' 'build/**/*.js' '.github/**/*.yml' gulpfile.js", "format-fix": "prettier --write 'src/**/*.ts' 'build/**/*.js' '.github/**/*.yml' gulpfile.js", "clean": "gulp clean", diff --git a/src/client/activation/node/analysisOptions.ts b/src/client/activation/node/analysisOptions.ts index 71295649c25a..1722da027a70 100644 --- a/src/client/activation/node/analysisOptions.ts +++ b/src/client/activation/node/analysisOptions.ts @@ -19,9 +19,9 @@ export class NodeLanguageServerAnalysisOptions extends LanguageServerAnalysisOpt // eslint-disable-next-line class-methods-use-this protected async getInitializationOptions(): Promise { - return ({ + return { experimentationSupport: true, trustedWorkspaceSupport: true, - } as unknown) as LanguageClientOptions; + } as unknown as LanguageClientOptions; } } diff --git a/src/client/activation/node/languageClientFactory.ts b/src/client/activation/node/languageClientFactory.ts index 9543f265468f..adc4e8ce55e5 100644 --- a/src/client/activation/node/languageClientFactory.ts +++ b/src/client/activation/node/languageClientFactory.ts @@ -22,8 +22,9 @@ export class NodeLanguageClientFactory implements ILanguageClientFactory { clientOptions: LanguageClientOptions, ): Promise { // this must exist for node language client - const commandArgs = (clientOptions.connectionOptions - ?.cancellationStrategy as FileBasedCancellationStrategy).getCommandLineArguments(); + const commandArgs = ( + clientOptions.connectionOptions?.cancellationStrategy as FileBasedCancellationStrategy + ).getCommandLineArguments(); const extension = this.extensions.getExtension(PYLANCE_EXTENSION_ID); const languageServerFolder = extension ? extension.extensionPath : ''; diff --git a/src/client/api.ts b/src/client/api.ts index 15fb4d688a89..d83d4db005a8 100644 --- a/src/client/api.ts +++ b/src/client/api.ts @@ -90,9 +90,7 @@ export function buildApi( * * When no resource is provided, the setting scoped to the first workspace folder is returned. * * If no folder is present, it returns the global setting. */ - getExecutionDetails( - resource?: Resource, - ): { + getExecutionDetails(resource?: Resource): { /** * E.g of execution commands returned could be, * * `['']` diff --git a/src/client/application/diagnostics/checks/invalidPythonPathInDebugger.ts b/src/client/application/diagnostics/checks/invalidPythonPathInDebugger.ts index f08c09956838..0f2b0fbb4673 100644 --- a/src/client/application/diagnostics/checks/invalidPythonPathInDebugger.ts +++ b/src/client/application/diagnostics/checks/invalidPythonPathInDebugger.ts @@ -53,8 +53,10 @@ class InvalidPythonPathInDebuggerDiagnostic extends BaseDiagnostic { export const InvalidPythonPathInDebuggerServiceId = 'InvalidPythonPathInDebuggerServiceId'; @injectable() -export class InvalidPythonPathInDebuggerService extends BaseDiagnosticsService - implements IInvalidPythonPathInDebuggerService { +export class InvalidPythonPathInDebuggerService + extends BaseDiagnosticsService + implements IInvalidPythonPathInDebuggerService +{ constructor( @inject(IServiceContainer) serviceContainer: IServiceContainer, @inject(IWorkspaceService) private readonly workspace: IWorkspaceService, diff --git a/src/client/application/diagnostics/checks/pythonInterpreter.ts b/src/client/application/diagnostics/checks/pythonInterpreter.ts index 31da53e75357..d74aa88e1dbd 100644 --- a/src/client/application/diagnostics/checks/pythonInterpreter.ts +++ b/src/client/application/diagnostics/checks/pythonInterpreter.ts @@ -91,8 +91,10 @@ export class DefaultShellDiagnostic extends BaseDiagnostic { export const InvalidPythonInterpreterServiceId = 'InvalidPythonInterpreterServiceId'; @injectable() -export class InvalidPythonInterpreterService extends BaseDiagnosticsService - implements IExtensionSingleActivationService { +export class InvalidPythonInterpreterService + extends BaseDiagnosticsService + implements IExtensionSingleActivationService +{ public readonly supportedWorkspaceTypes = { untrustedWorkspace: false, virtualWorkspace: true }; constructor( diff --git a/src/client/common/application/applicationEnvironment.ts b/src/client/common/application/applicationEnvironment.ts index 4b66893d6c0b..34f4ba31b850 100644 --- a/src/client/common/application/applicationEnvironment.ts +++ b/src/client/common/application/applicationEnvironment.ts @@ -41,6 +41,7 @@ export class ApplicationEnvironment implements IApplicationEnvironment { ? path.join(this.process.env.APPDATA, vscodeFolderName, 'User', 'settings.json') : undefined; default: + // eslint-disable-next-line getter-return return; } } diff --git a/src/client/common/application/commandManager.ts b/src/client/common/application/commandManager.ts index 9e1f34a5885b..9e377dc0629c 100644 --- a/src/client/common/application/commandManager.ts +++ b/src/client/common/application/commandManager.ts @@ -23,7 +23,7 @@ export class CommandManager implements ICommandManager { // eslint-disable-next-line class-methods-use-this public registerCommand< E extends keyof ICommandNameArgumentTypeMapping, - U extends ICommandNameArgumentTypeMapping[E] + U extends ICommandNameArgumentTypeMapping[E], // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any >(command: E, callback: (...args: U) => any, thisArg?: any): Disposable { // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -73,7 +73,7 @@ export class CommandManager implements ICommandManager { public executeCommand< T, E extends keyof ICommandNameArgumentTypeMapping, - U extends ICommandNameArgumentTypeMapping[E] + U extends ICommandNameArgumentTypeMapping[E], >(command: E, ...rest: U): Thenable { return commands.executeCommand(command, ...rest); } diff --git a/src/client/common/application/commands/reportIssueCommand.ts b/src/client/common/application/commands/reportIssueCommand.ts index e5633f4a4389..c9f40d861958 100644 --- a/src/client/common/application/commands/reportIssueCommand.ts +++ b/src/client/common/application/commands/reportIssueCommand.ts @@ -61,7 +61,7 @@ export class ReportIssueCommandHandler implements IExtensionSingleActivationServ if (argSetting) { if (typeof argSetting === 'object') { let propertyHeaderAdded = false; - const argSettingsDict = (settings[property] as unknown) as Record; + const argSettingsDict = settings[property] as unknown as Record; if (typeof argSettingsDict === 'object') { Object.keys(argSetting).forEach((item) => { const prop = argSetting[item]; diff --git a/src/client/common/extensions.ts b/src/client/common/extensions.ts index 033a375b1e56..957ec99a7ce1 100644 --- a/src/client/common/extensions.ts +++ b/src/client/common/extensions.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// eslint-disable-next-line @typescript-eslint/no-unused-vars declare interface String { /** * Appropriately formats a string so it can be used as an argument for a command in a shell. diff --git a/src/client/common/installer/channelManager.ts b/src/client/common/installer/channelManager.ts index d2950859ab80..7aec230620f9 100644 --- a/src/client/common/installer/channelManager.ts +++ b/src/client/common/installer/channelManager.ts @@ -42,7 +42,7 @@ export class InstallationChannelManager implements IInstallationChannelManager { installer, }; }); - const selection = await appShell.showQuickPick(options, { + const selection = await appShell.showQuickPick<(typeof options)[0]>(options, { matchOnDescription: true, matchOnDetail: true, placeHolder, diff --git a/src/client/common/process/currentProcess.ts b/src/client/common/process/currentProcess.ts index b80c32e97b7c..4d549630279f 100644 --- a/src/client/common/process/currentProcess.ts +++ b/src/client/common/process/currentProcess.ts @@ -13,7 +13,7 @@ export class CurrentProcess implements ICurrentProcess { return process as any; }; public get env(): EnvironmentVariables { - return (process.env as any) as EnvironmentVariables; + return process.env as any as EnvironmentVariables; } public get argv(): string[] { return process.argv; diff --git a/src/client/common/process/pythonExecutionFactory.ts b/src/client/common/process/pythonExecutionFactory.ts index efb05c3c9d12..996f58e4154e 100644 --- a/src/client/common/process/pythonExecutionFactory.ts +++ b/src/client/common/process/pythonExecutionFactory.ts @@ -53,9 +53,8 @@ export class PythonExecutionFactory implements IPythonExecutionFactory { public async create(options: ExecutionFactoryCreationOptions): Promise { let { pythonPath } = options; if (!pythonPath || pythonPath === 'python') { - const activatedEnvLaunch = this.serviceContainer.get( - IActivatedEnvironmentLaunch, - ); + const activatedEnvLaunch = + this.serviceContainer.get(IActivatedEnvironmentLaunch); await activatedEnvLaunch.selectIfLaunchedViaActivatedEnv(); // If python path wasn't passed in, we need to auto select it and then read it // from the configuration. diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index a051d66f015f..e92fbd3d494f 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -94,6 +94,7 @@ export class TerminalService implements ITerminalService, Disposable { this._terminalFirstLaunched = false; const promise = new Promise((resolve) => { const disposable = this.terminalManager.onDidChangeTerminalShellIntegration(() => { + // eslint-disable-next-line @typescript-eslint/no-use-before-define clearTimeout(timer); disposable.dispose(); resolve(true); diff --git a/src/client/common/utils/async.ts b/src/client/common/utils/async.ts index cabea8225ac9..67066d7597c4 100644 --- a/src/client/common/utils/async.ts +++ b/src/client/common/utils/async.ts @@ -115,9 +115,9 @@ export interface IAsyncIterableIterator extends IAsyncIterator, AsyncItera * An iterator that yields nothing. */ export function iterEmpty(): IAsyncIterableIterator { - return ((async function* () { + return (async function* () { /** No body. */ - })() as unknown) as IAsyncIterableIterator; + })() as unknown as IAsyncIterableIterator; } type NextResult = { index: number } & ( diff --git a/src/client/common/utils/cacheUtils.ts b/src/client/common/utils/cacheUtils.ts index 6101b3ef928f..5cefafaea03d 100644 --- a/src/client/common/utils/cacheUtils.ts +++ b/src/client/common/utils/cacheUtils.ts @@ -48,6 +48,7 @@ export class InMemoryCache { */ public get data(): T | undefined { if (!this.hasData) { + // eslint-disable-next-line getter-return return; } return this.cacheData?.value; diff --git a/src/client/common/utils/enum.ts b/src/client/common/utils/enum.ts index 78104b48846f..1717ea51f5ba 100644 --- a/src/client/common/utils/enum.ts +++ b/src/client/common/utils/enum.ts @@ -12,7 +12,7 @@ function getNames(e: any) { } export function getValues(e: any) { - return (getObjValues(e).filter((v) => typeof v === 'number') as any) as T[]; + return getObjValues(e).filter((v) => typeof v === 'number') as any as T[]; } function getObjValues(e: any): (number | string)[] { diff --git a/src/client/common/utils/platform.ts b/src/client/common/utils/platform.ts index a1a49ba3c427..c16bcf1f01ca 100644 --- a/src/client/common/utils/platform.ts +++ b/src/client/common/utils/platform.ts @@ -53,7 +53,7 @@ export function getArchitecture(): Architecture { * Look up the requested env var value (or undefined` if not set). */ export function getEnvironmentVariable(key: string): string | undefined { - return ((process.env as any) as EnvironmentVariables)[key]; + return (process.env as any as EnvironmentVariables)[key]; } /** diff --git a/src/client/common/utils/resourceLifecycle.ts b/src/client/common/utils/resourceLifecycle.ts index b5d1a9a1c83a..e299f4222ea4 100644 --- a/src/client/common/utils/resourceLifecycle.ts +++ b/src/client/common/utils/resourceLifecycle.ts @@ -144,7 +144,7 @@ export class DisposableStore implements IDisposable { if (!o) { return o; } - if (((o as unknown) as DisposableStore) === this) { + if ((o as unknown as DisposableStore) === this) { throw new Error('Cannot register a disposable on itself!'); } @@ -191,7 +191,7 @@ export abstract class DisposableBase implements IDisposable { * Adds `o` to the collection of disposables managed by this object. */ public _register(o: T): T { - if (((o as unknown) as DisposableBase) === this) { + if ((o as unknown as DisposableBase) === this) { throw new Error('Cannot register a disposable on itself!'); } return this._store.add(o); diff --git a/src/client/common/utils/version.ts b/src/client/common/utils/version.ts index b3d9ed3d2f46..e98fd83f2a60 100644 --- a/src/client/common/utils/version.ts +++ b/src/client/common/utils/version.ts @@ -80,7 +80,7 @@ function copyStrict(info: T): RawBasicVersionInfo { micro: info.micro, }; - const { unnormalized } = (info as unknown) as RawBasicVersionInfo; + const { unnormalized } = info as unknown as RawBasicVersionInfo; if (unnormalized !== undefined) { copied.unnormalized = { major: unnormalized.major, @@ -134,7 +134,7 @@ function validateVersionPart(prop: string, part: number, unnormalized?: ErrorMsg * is responsible for any other properties beyond that. */ function validateBasicVersionInfo(info: T): void { - const raw = (info as unknown) as RawBasicVersionInfo; + const raw = info as unknown as RawBasicVersionInfo; validateVersionPart('major', info.major, raw.unnormalized?.major); validateVersionPart('minor', info.minor, raw.unnormalized?.minor); validateVersionPart('micro', info.micro, raw.unnormalized?.micro); @@ -224,7 +224,7 @@ export function parseBasicVersionInfo(verStr: string const micro = microStr ? parseInt(microStr, 10) : -1; return { // This is effectively normalized. - version: ({ major, minor, micro } as unknown) as T, + version: { major, minor, micro } as unknown as T, before: before || '', after: after || '', }; @@ -388,10 +388,10 @@ export function areSimilarVersions { - ((this as any) as Record)[`env:${key}`] = ((this as any) as Record< - string, - string | undefined - >)[`env.${key}`] = process.env[key]; + (this as any as Record)[`env:${key}`] = ( + this as any as Record + )[`env.${key}`] = process.env[key]; }); workspace = workspace ?? new WorkspaceService(); try { workspace.workspaceFolders?.forEach((folder) => { const basename = Path.basename(folder.uri.fsPath); - ((this as any) as Record)[`workspaceFolder:${basename}`] = - folder.uri.fsPath; - ((this as any) as Record)[`workspaceFolder:${folder.name}`] = + (this as any as Record)[`workspaceFolder:${basename}`] = folder.uri.fsPath; + (this as any as Record)[`workspaceFolder:${folder.name}`] = folder.uri.fsPath; }); } catch { diff --git a/src/client/debugger/extension/configuration/resolvers/base.ts b/src/client/debugger/extension/configuration/resolvers/base.ts index fde55ad8d5ea..1958a910a3ba 100644 --- a/src/client/debugger/extension/configuration/resolvers/base.ts +++ b/src/client/debugger/extension/configuration/resolvers/base.ts @@ -21,7 +21,8 @@ import { getProgram } from './helper'; @injectable() export abstract class BaseConfigurationResolver - implements IDebugConfigurationResolver { + implements IDebugConfigurationResolver +{ protected pythonPathSource: PythonPathSource = PythonPathSource.launchJson; constructor( diff --git a/src/client/deprecatedProposedApiTypes.ts b/src/client/deprecatedProposedApiTypes.ts index eb76d61dc907..40b4557e207e 100644 --- a/src/client/deprecatedProposedApiTypes.ts +++ b/src/client/deprecatedProposedApiTypes.ts @@ -58,9 +58,7 @@ export interface DeprecatedProposedAPI { * * When no resource is provided, the setting scoped to the first workspace folder is returned. * * If no folder is present, it returns the global setting. */ - getExecutionDetails( - resource?: Resource, - ): Promise<{ + getExecutionDetails(resource?: Resource): Promise<{ /** * E.g of execution commands returned could be, * * `['']` diff --git a/src/client/envExt/api.internal.ts b/src/client/envExt/api.internal.ts index 7d511eac49ea..cb3ff92b51b3 100644 --- a/src/client/envExt/api.internal.ts +++ b/src/client/envExt/api.internal.ts @@ -26,9 +26,8 @@ export function useEnvExtension(): boolean { return _useExt; } -const onDidChangeEnvironmentEnvExtEmitter: EventEmitter = new EventEmitter< - DidChangeEnvironmentEventArgs ->(); +const onDidChangeEnvironmentEnvExtEmitter: EventEmitter = + new EventEmitter(); export function onDidChangeEnvironmentEnvExt( listener: (e: DidChangeEnvironmentEventArgs) => unknown, thisArgs?: unknown, diff --git a/src/client/extension.ts b/src/client/extension.ts index 521a8878ab63..4404cae24491 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -188,9 +188,9 @@ interface IAppShell { function notifyUser(msg: string) { try { - let appShell: IAppShell = (window as any) as IAppShell; + let appShell: IAppShell = window as any as IAppShell; if (activatedServiceContainer) { - appShell = (activatedServiceContainer.get(IApplicationShell) as any) as IAppShell; + appShell = activatedServiceContainer.get(IApplicationShell) as any as IAppShell; } appShell.showErrorMessage(msg).ignoreErrors(); } catch (ex) { diff --git a/src/client/extensionActivation.ts b/src/client/extensionActivation.ts index 362fcf8468ad..5045a1d7fecf 100644 --- a/src/client/extensionActivation.ts +++ b/src/client/extensionActivation.ts @@ -93,15 +93,12 @@ export async function activateComponents( } export function activateFeatures(ext: ExtensionState, _components: Components): void { - const interpreterQuickPick: IInterpreterQuickPick = ext.legacyIOC.serviceContainer.get( - IInterpreterQuickPick, - ); - const interpreterPathService: IInterpreterPathService = ext.legacyIOC.serviceContainer.get( - IInterpreterPathService, - ); - const interpreterService: IInterpreterService = ext.legacyIOC.serviceContainer.get( - IInterpreterService, - ); + const interpreterQuickPick: IInterpreterQuickPick = + ext.legacyIOC.serviceContainer.get(IInterpreterQuickPick); + const interpreterPathService: IInterpreterPathService = + ext.legacyIOC.serviceContainer.get(IInterpreterPathService); + const interpreterService: IInterpreterService = + ext.legacyIOC.serviceContainer.get(IInterpreterService); registerEnvExtFeatures(ext.disposables, interpreterPathService); const pathUtils = ext.legacyIOC.serviceContainer.get(IPathUtils); registerPixiFeatures(ext.disposables); diff --git a/src/client/interpreter/autoSelection/index.ts b/src/client/interpreter/autoSelection/index.ts index 5ad5362e8210..a6ab4f7aa674 100644 --- a/src/client/interpreter/autoSelection/index.ts +++ b/src/client/interpreter/autoSelection/index.ts @@ -31,12 +31,11 @@ export class InterpreterAutoSelectionService implements IInterpreterAutoSelectio private readonly autoSelectedInterpreterByWorkspace = new Map(); - private globallyPreferredInterpreter: IPersistentState< - PythonEnvironment | undefined - > = this.stateFactory.createGlobalPersistentState( - preferredGlobalInterpreter, - undefined, - ); + private globallyPreferredInterpreter: IPersistentState = + this.stateFactory.createGlobalPersistentState( + preferredGlobalInterpreter, + undefined, + ); constructor( @inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService, diff --git a/src/client/interpreter/configuration/interpreterSelector/commands/base.ts b/src/client/interpreter/configuration/interpreterSelector/commands/base.ts index 6307e286dbfe..e55ad051a9f4 100644 --- a/src/client/interpreter/configuration/interpreterSelector/commands/base.ts +++ b/src/client/interpreter/configuration/interpreterSelector/commands/base.ts @@ -35,9 +35,7 @@ export abstract class BaseInterpreterSelectorCommand implements IExtensionSingle public abstract activate(): Promise; - protected async getConfigTargets(options?: { - resetTarget?: boolean; - }): Promise< + protected async getConfigTargets(options?: { resetTarget?: boolean }): Promise< | { folderUri: Resource; configTarget: ConfigurationTarget; diff --git a/src/client/interpreter/interpreterService.ts b/src/client/interpreter/interpreterService.ts index 3a1aaed312ff..0dd51b8425df 100644 --- a/src/client/interpreter/interpreterService.ts +++ b/src/client/interpreter/interpreterService.ts @@ -234,9 +234,8 @@ export class InterpreterService implements Disposable, IInterpreterService { // Note the following triggers autoselection if no interpreter is explictly // selected, i.e the value is `python`. // During shutdown we might not be able to get items out of the service container. - const pythonExecutionFactory = this.serviceContainer.tryGet( - IPythonExecutionFactory, - ); + const pythonExecutionFactory = + this.serviceContainer.tryGet(IPythonExecutionFactory); const pythonExecutionService = pythonExecutionFactory ? await pythonExecutionFactory.create({ resource }) : undefined; diff --git a/src/client/jupyter/jupyterIntegration.ts b/src/client/jupyter/jupyterIntegration.ts index 1136502c1ef2..10d4443d9de0 100644 --- a/src/client/jupyter/jupyterIntegration.ts +++ b/src/client/jupyter/jupyterIntegration.ts @@ -183,9 +183,7 @@ export interface JupyterPythonEnvironmentApi { * If the Uri is not associated with a Jupyter Notebook or Interactive Window, then this method returns undefined. * @param uri */ - getPythonEnvironment?( - uri: Uri, - ): + getPythonEnvironment?(uri: Uri): | undefined | { /** @@ -213,9 +211,7 @@ export class JupyterExtensionPythonEnvironments extends DisposableBase implement super(); } - public getPythonEnvironment( - uri: Uri, - ): + public getPythonEnvironment(uri: Uri): | undefined | { /** diff --git a/src/client/logging/index.ts b/src/client/logging/index.ts index 39d5652e100a..1390e06b4b70 100644 --- a/src/client/logging/index.ts +++ b/src/client/logging/index.ts @@ -126,7 +126,7 @@ function tracing(log: (t: TraceInfo) => void, run: () => T): T { // If method being wrapped returns a promise then wait for it. if (isPromise(result)) { - ((result as unknown) as Promise) + (result as unknown as Promise) .then((data) => { log({ elapsed: timer.elapsedTime, returnValue: data }); return data; @@ -191,7 +191,7 @@ function logResult(logInfo: LogInfo, traced: TraceInfo, call?: CallInfo) { } } else { logTo(LogLevel.Error, [formatted, traced.err]); - sendTelemetryEvent(('ERROR' as unknown) as EventName, undefined, undefined, traced.err); + sendTelemetryEvent('ERROR' as unknown as EventName, undefined, undefined, traced.err); } } diff --git a/src/client/pythonEnvironments/base/info/pythonVersion.ts b/src/client/pythonEnvironments/base/info/pythonVersion.ts index 589bf4c7b7af..8fca961862bf 100644 --- a/src/client/pythonEnvironments/base/info/pythonVersion.ts +++ b/src/client/pythonEnvironments/base/info/pythonVersion.ts @@ -235,9 +235,7 @@ function compareVersionRelease(left: PythonVersion, right: PythonVersion): [numb * Remarks: primarily used to convert to old type of environment info. * @deprecated */ -export function toSemverLikeVersion( - version: PythonVersion, -): { +export function toSemverLikeVersion(version: PythonVersion): { raw: string; major: number; minor: number; diff --git a/src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts b/src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts index cb5ab63077c9..b2c8b968024a 100644 --- a/src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts +++ b/src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts @@ -272,9 +272,10 @@ class NativePythonFinderImpl extends DisposableBase implements NativePythonFinde return connection; } - private doRefresh( - options?: NativePythonEnvironmentKind | Uri[], - ): { completed: Promise; discovered: Event } { + private doRefresh(options?: NativePythonEnvironmentKind | Uri[]): { + completed: Promise; + discovered: Event; + } { const disposable = this._register(new DisposableStore()); const discovered = disposable.add(new EventEmitter()); const completed = createDeferred(); @@ -433,7 +434,7 @@ function getCustomVirtualEnvDirs(): string[] { function getPythonSettingAndUntildify(name: string, scope?: Uri): T | undefined { const value = getConfiguration('python', scope).get(name); if (typeof value === 'string') { - return value ? ((untildify(value as string) as unknown) as T) : undefined; + return value ? (untildify(value as string) as unknown as T) : undefined; } return value; } @@ -452,7 +453,7 @@ export function getNativePythonFinder(context?: IExtensionContext): NativePython }, async getCondaInfo() { traceError('Python discovery not supported in untrusted workspace'); - return ({} as unknown) as NativeCondaInfo; + return {} as unknown as NativeCondaInfo; }, dispose() { // do nothing diff --git a/src/client/pythonEnvironments/base/locators/composite/envsCollectionCache.ts b/src/client/pythonEnvironments/base/locators/composite/envsCollectionCache.ts index 456e8adfa9a4..0c63a2b13256 100644 --- a/src/client/pythonEnvironments/base/locators/composite/envsCollectionCache.ts +++ b/src/client/pythonEnvironments/base/locators/composite/envsCollectionCache.ts @@ -67,8 +67,10 @@ interface IPersistentStorage { /** * Environment info cache using persistent storage to save and retrieve pre-cached env info. */ -export class PythonEnvInfoCache extends PythonEnvsWatcher - implements IEnvsCollectionCache { +export class PythonEnvInfoCache + extends PythonEnvsWatcher + implements IEnvsCollectionCache +{ private envs: PythonEnvInfo[] = []; /** diff --git a/src/client/pythonEnvironments/common/environmentManagers/condaService.ts b/src/client/pythonEnvironments/common/environmentManagers/condaService.ts index 0739993dad37..fdf659b9a33e 100644 --- a/src/client/pythonEnvironments/common/environmentManagers/condaService.ts +++ b/src/client/pythonEnvironments/common/environmentManagers/condaService.ts @@ -25,9 +25,8 @@ export class CondaService implements ICondaService { ): Promise<{ path: string | undefined; type: 'local' | 'global' } | undefined> { const condaPath = await this.getCondaFileFromInterpreter(interpreterPath, envName); - const activatePath = (condaPath - ? path.join(path.dirname(condaPath), 'activate') - : 'activate' + const activatePath = ( + condaPath ? path.join(path.dirname(condaPath), 'activate') : 'activate' ).fileToCommandArgumentForPythonExt(); // maybe global activate? // try to find the activate script in the global conda root prefix. diff --git a/src/client/pythonEnvironments/creation/createEnvApi.ts b/src/client/pythonEnvironments/creation/createEnvApi.ts index ab0f0db317c3..4e4ea7572615 100644 --- a/src/client/pythonEnvironments/creation/createEnvApi.ts +++ b/src/client/pythonEnvironments/creation/createEnvApi.ts @@ -89,13 +89,10 @@ export function registerCreateEnvironmentFeatures( return undefined; }, ), - registerCommand( - Commands.Create_Environment_Button, - async (): Promise => { - sendTelemetryEvent(EventName.ENVIRONMENT_BUTTON, undefined, undefined); - await executeCommand(Commands.Create_Environment); - }, - ), + registerCommand(Commands.Create_Environment_Button, async (): Promise => { + sendTelemetryEvent(EventName.ENVIRONMENT_BUTTON, undefined, undefined); + await executeCommand(Commands.Create_Environment); + }), registerCreateEnvironmentProvider(new VenvCreationProvider(interpreterQuickPick)), registerCreateEnvironmentProvider(condaCreationProvider()), onCreateEnvironmentExited(async (e: EnvironmentDidCreateEvent) => { diff --git a/src/client/pythonEnvironments/index.ts b/src/client/pythonEnvironments/index.ts index 299dfab59132..0e862c4f448b 100644 --- a/src/client/pythonEnvironments/index.ts +++ b/src/client/pythonEnvironments/index.ts @@ -255,7 +255,7 @@ function putIntoStorage(storage: IPersistentStorage, envs: Pyth if (e.searchLocation) { // Make TS believe it is string. This is temporary. We need to serialize this in // a custom way. - e.searchLocation = (e.searchLocation.toString() as unknown) as Uri; + e.searchLocation = e.searchLocation.toString() as unknown as Uri; } return e; }), diff --git a/src/client/repl/replUtils.ts b/src/client/repl/replUtils.ts index 8e23218c2870..7164a277df9b 100644 --- a/src/client/repl/replUtils.ts +++ b/src/client/repl/replUtils.ts @@ -87,7 +87,7 @@ export function getExistingReplViewColumn(notebookDocument: NotebookDocument): V for (const tabGroup of ourTb.all) { for (const tab of tabGroup.tabs) { if (tab.label === 'Python REPL') { - const tabInput = (tab.input as unknown) as TabInputNotebook; + const tabInput = tab.input as unknown as TabInputNotebook; const tabUri = tabInput.uri.toString(); if (tab.input && tabUri === ourNotebookUri) { // This is the tab we are looking for. diff --git a/src/client/telemetry/importTracker.ts b/src/client/telemetry/importTracker.ts index cf8e1ed48837..1e8b96fcfc12 100644 --- a/src/client/telemetry/importTracker.ts +++ b/src/client/telemetry/importTracker.ts @@ -40,7 +40,8 @@ Things we are ignoring the following for simplicity/performance: - Non-standard whitespace separators within the import statement (i.e. more than a single space, tabs) */ -const ImportRegEx = /^\s*(from (?\w+)(?:\.\w+)* import \w+(?:, \w+)*(?: as \w+)?|import (?\w+(?:, \w+)*)(?: as \w+)?)$/; +const ImportRegEx = + /^\s*(from (?\w+)(?:\.\w+)* import \w+(?:, \w+)*(?: as \w+)?|import (?\w+(?:, \w+)*)(?: as \w+)?)$/; const MAX_DOCUMENT_LINES = 1000; // Capture isTestExecution on module load so that a test can turn it off and still diff --git a/src/client/tensorBoard/helpers.ts b/src/client/tensorBoard/helpers.ts index 8da3ef6a38f2..90a6eb3e8ab6 100644 --- a/src/client/tensorBoard/helpers.ts +++ b/src/client/tensorBoard/helpers.ts @@ -8,4 +8,5 @@ // matches the 'main' module. // RegEx to match `import torch.profiler` or `from torch import profiler` -export const TorchProfilerImportRegEx = /^\s*(?:import (?:(\w+, )*torch\.profiler(, \w+)*))|(?:from torch import (?:(\w+, )*profiler(, \w+)*))/; +export const TorchProfilerImportRegEx = + /^\s*(?:import (?:(\w+, )*torch\.profiler(, \w+)*))|(?:from torch import (?:(\w+, )*profiler(, \w+)*))/; diff --git a/src/client/testing/main.ts b/src/client/testing/main.ts index c2675ed4a72b..49531a1e11b3 100644 --- a/src/client/testing/main.ts +++ b/src/client/testing/main.ts @@ -72,6 +72,7 @@ export class UnitTestManagementService implements IExtensionActivationService { this.registerHandlers(); this.registerCommands(); + // eslint-disable-next-line no-extra-boolean-cast if (!!tests.testResults) { await this.updateTestUIButtons(); this.disposableRegistry.push( @@ -170,31 +171,32 @@ export class UnitTestManagementService implements IExtensionActivationService { this.testController?.refreshTestData(resource, { forceRefresh: true }); }, ), - commandManager.registerCommand(constants.Commands.Tests_CopilotSetup, (resource?: Uri): - | { message: string; command: Command } - | undefined => { - const wkspaceFolder = - this.workspaceService.getWorkspaceFolder(resource) || this.workspaceService.workspaceFolders?.at(0); - if (!wkspaceFolder) { - return undefined; - } + commandManager.registerCommand( + constants.Commands.Tests_CopilotSetup, + (resource?: Uri): { message: string; command: Command } | undefined => { + const wkspaceFolder = + this.workspaceService.getWorkspaceFolder(resource) || + this.workspaceService.workspaceFolders?.at(0); + if (!wkspaceFolder) { + return undefined; + } - const configurationService = this.serviceContainer.get( - ITestConfigurationService, - ); - if (configurationService.hasConfiguredTests(wkspaceFolder.uri)) { - return undefined; - } + const configurationService = + this.serviceContainer.get(ITestConfigurationService); + if (configurationService.hasConfiguredTests(wkspaceFolder.uri)) { + return undefined; + } - return { - message: Testing.copilotSetupMessage, - command: { - title: Testing.configureTests, - command: constants.Commands.Tests_Configure, - arguments: [undefined, constants.CommandSource.ui, resource], - }, - }; - }), + return { + message: Testing.copilotSetupMessage, + command: { + title: Testing.configureTests, + command: constants.Commands.Tests_Configure, + arguments: [undefined, constants.CommandSource.ui, resource], + }, + }; + }, + ), ); } diff --git a/src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts b/src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts index 71d71997c57e..8c2ca303d1e6 100644 --- a/src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts +++ b/src/client/testing/testController/pytest/pytestDiscoveryAdapter.ts @@ -127,7 +127,7 @@ export class PytestTestDiscoveryAdapter implements ITestDiscoveryAdapter { const proc = await runInBackground(pythonEnv, { cwd, args: execArgs, - env: (mutableEnv as unknown) as { [key: string]: string }, + env: mutableEnv as unknown as { [key: string]: string }, }); token?.onCancellationRequested(() => { traceInfo(`Test discovery cancelled, killing pytest subprocess for workspace ${uri.fsPath}`); diff --git a/src/client/testing/testController/pytest/pytestExecutionAdapter.ts b/src/client/testing/testController/pytest/pytestExecutionAdapter.ts index 3a824f79ac63..a084ef1a6213 100644 --- a/src/client/testing/testController/pytest/pytestExecutionAdapter.ts +++ b/src/client/testing/testController/pytest/pytestExecutionAdapter.ts @@ -183,7 +183,7 @@ export class PytestTestExecutionAdapter implements ITestExecutionAdapter { const proc = await runInBackground(pythonEnv, { cwd, args: runArgs, - env: (mutableEnv as unknown) as { [key: string]: string }, + env: mutableEnv as unknown as { [key: string]: string }, }); runInstance?.token.onCancellationRequested(() => { traceInfo(`Test run cancelled, killing pytest subprocess for workspace ${uri.fsPath}`); diff --git a/src/client/testing/testController/unittest/testDiscoveryAdapter.ts b/src/client/testing/testController/unittest/testDiscoveryAdapter.ts index 7e478b25735a..7afadcefd052 100644 --- a/src/client/testing/testController/unittest/testDiscoveryAdapter.ts +++ b/src/client/testing/testController/unittest/testDiscoveryAdapter.ts @@ -117,7 +117,7 @@ export class UnittestTestDiscoveryAdapter implements ITestDiscoveryAdapter { const proc = await runInBackground(pythonEnv, { cwd, args, - env: (mutableEnv as unknown) as { [key: string]: string }, + env: mutableEnv as unknown as { [key: string]: string }, }); options.token?.onCancellationRequested(() => { traceInfo(`Test discovery cancelled, killing unittest subprocess for workspace ${uri.fsPath}`); diff --git a/src/client/testing/testController/unittest/testExecutionAdapter.ts b/src/client/testing/testController/unittest/testExecutionAdapter.ts index e46e8c436583..15cdaa12f3aa 100644 --- a/src/client/testing/testController/unittest/testExecutionAdapter.ts +++ b/src/client/testing/testController/unittest/testExecutionAdapter.ts @@ -194,7 +194,7 @@ export class UnittestTestExecutionAdapter implements ITestExecutionAdapter { const proc = await runInBackground(pythonEnv, { cwd, args, - env: (mutableEnv as unknown) as { [key: string]: string }, + env: mutableEnv as unknown as { [key: string]: string }, }); runInstance?.token.onCancellationRequested(() => { traceInfo(`Test run cancelled, killing unittest subprocess for workspace ${uri.fsPath}`); diff --git a/src/test/activation/activationManager.unit.test.ts b/src/test/activation/activationManager.unit.test.ts index 6ee2572214b8..315a4e3c6fb9 100644 --- a/src/test/activation/activationManager.unit.test.ts +++ b/src/test/activation/activationManager.unit.test.ts @@ -180,8 +180,8 @@ suite('Activation Manager', () => { const disposable2 = typemoq.Mock.ofType(); when(workspaceService.onDidChangeWorkspaceFolders).thenReturn(() => disposable.object); when(workspaceService.workspaceFolders).thenReturn([ - (1 as unknown) as WorkspaceFolder, - (2 as unknown) as WorkspaceFolder, + 1 as unknown as WorkspaceFolder, + 2 as unknown as WorkspaceFolder, ]); const eventDef = () => disposable2.object; documentManager @@ -209,8 +209,8 @@ suite('Activation Manager', () => { const disposable2 = typemoq.Mock.ofType(); when(workspaceService.onDidChangeWorkspaceFolders).thenReturn(() => disposable.object); when(workspaceService.workspaceFolders).thenReturn([ - (1 as unknown) as WorkspaceFolder, - (2 as unknown) as WorkspaceFolder, + 1 as unknown as WorkspaceFolder, + 2 as unknown as WorkspaceFolder, ]); const eventDef = () => disposable2.object; documentManager @@ -328,7 +328,7 @@ suite('Activation Manager', () => { languageId: 'NOT PYTHON', }; - managerTest.onDocOpened((doc as unknown) as TextDocument); + managerTest.onDocOpened(doc as unknown as TextDocument); verify(workspaceService.getWorkspaceFolderIdentifier(doc.uri, anything())).never(); }); @@ -339,7 +339,7 @@ suite('Activation Manager', () => { }; when(workspaceService.getWorkspaceFolderIdentifier(doc.uri, anything())).thenReturn(''); - managerTest.onDocOpened((doc as unknown) as TextDocument); + managerTest.onDocOpened(doc as unknown as TextDocument); verify(workspaceService.getWorkspaceFolderIdentifier(doc.uri, anything())).once(); verify(workspaceService.getWorkspaceFolder(doc.uri)).once(); @@ -353,7 +353,7 @@ suite('Activation Manager', () => { when(workspaceService.getWorkspaceFolderIdentifier(doc.uri, anything())).thenReturn('key'); managerTest.activatedWorkspaces.add('key'); - managerTest.onDocOpened((doc as unknown) as TextDocument); + managerTest.onDocOpened(doc as unknown as TextDocument); verify(workspaceService.getWorkspaceFolderIdentifier(doc.uri, anything())).once(); verify(workspaceService.getWorkspaceFolder(doc.uri)).never(); diff --git a/src/test/activation/partialModeStatus.unit.test.ts b/src/test/activation/partialModeStatus.unit.test.ts index 12e4b6fc0c5b..67fb66e9014b 100644 --- a/src/test/activation/partialModeStatus.unit.test.ts +++ b/src/test/activation/partialModeStatus.unit.test.ts @@ -20,15 +20,15 @@ suite('Partial Mode Status', async () => { let vscodeMock: typeof vscodeTypes; setup(() => { workspaceService = typemoq.Mock.ofType(); - languageItem = ({ + languageItem = { name: '', severity: 2, text: '', detail: undefined, command: undefined, - } as unknown) as LanguageStatusItem; + } as unknown as LanguageStatusItem; actualSelector = undefined; - vscodeMock = ({ + vscodeMock = { languages: { createLanguageStatusItem: (_: string, selector: DocumentSelector) => { actualSelector = selector; @@ -43,7 +43,7 @@ suite('Partial Mode Status', async () => { Uri: { parse: (s: string) => s, }, - } as unknown) as typeof vscodeTypes; + } as unknown as typeof vscodeTypes; rewiremock.enable(); rewiremock('vscode').with(vscodeMock); }); @@ -78,7 +78,7 @@ suite('Partial Mode Status', async () => { assert.deepEqual(actualSelector!, { language: 'python', }); - assert.deepEqual(languageItem, ({ + assert.deepEqual(languageItem, { name: LanguageService.statusItem.name, severity: vscodeMock.LanguageStatusSeverity.Warning, text: LanguageService.statusItem.text, @@ -88,7 +88,7 @@ suite('Partial Mode Status', async () => { command: 'vscode.open', arguments: ['https://aka.ms/AAdzyh4'], }, - } as unknown) as LanguageStatusItem); + } as unknown as LanguageStatusItem); }); test('Expected status item is created if workspace is virtual', async () => { @@ -104,7 +104,7 @@ suite('Partial Mode Status', async () => { assert.deepEqual(actualSelector!, { language: 'python', }); - assert.deepEqual(languageItem, ({ + assert.deepEqual(languageItem, { name: LanguageService.statusItem.name, severity: vscodeMock.LanguageStatusSeverity.Warning, text: LanguageService.statusItem.text, @@ -114,7 +114,7 @@ suite('Partial Mode Status', async () => { command: 'vscode.open', arguments: ['https://aka.ms/AAdzyh4'], }, - } as unknown) as LanguageStatusItem); + } as unknown as LanguageStatusItem); }); test('Expected status item is created if workspace is both virtual and untrusted', async () => { @@ -130,7 +130,7 @@ suite('Partial Mode Status', async () => { assert.deepEqual(actualSelector!, { language: 'python', }); - assert.deepEqual(languageItem, ({ + assert.deepEqual(languageItem, { name: LanguageService.statusItem.name, severity: vscodeMock.LanguageStatusSeverity.Warning, text: LanguageService.statusItem.text, @@ -140,6 +140,6 @@ suite('Partial Mode Status', async () => { command: 'vscode.open', arguments: ['https://aka.ms/AAdzyh4'], }, - } as unknown) as LanguageStatusItem); + } as unknown as LanguageStatusItem); }); }); diff --git a/src/test/application/diagnostics/checks/jediPython27NotSupported.unit.test.ts b/src/test/application/diagnostics/checks/jediPython27NotSupported.unit.test.ts index d4af2e5ca901..1036d35b059e 100644 --- a/src/test/application/diagnostics/checks/jediPython27NotSupported.unit.test.ts +++ b/src/test/application/diagnostics/checks/jediPython27NotSupported.unit.test.ts @@ -34,21 +34,22 @@ suite('Application Diagnostics - Jedi with Python 2.7 deprecated', () => { suite('Diagnostics', () => { const resource = Uri.file('test.py'); - function createConfigurationAndWorkspaceServices( - languageServer: LanguageServerType, - ): { configurationService: IConfigurationService; workspaceService: IWorkspaceService } { - const configurationService = ({ + function createConfigurationAndWorkspaceServices(languageServer: LanguageServerType): { + configurationService: IConfigurationService; + workspaceService: IWorkspaceService; + } { + const configurationService = { getSettings: () => ({ languageServer }), updateSetting: () => Promise.resolve(), - } as unknown) as IConfigurationService; + } as unknown as IConfigurationService; - const workspaceService = ({ + const workspaceService = { getConfiguration: () => ({ inspect: () => ({ workspaceValue: languageServer, }), }), - } as unknown) as IWorkspaceService; + } as unknown as IWorkspaceService; return { configurationService, workspaceService }; } @@ -70,9 +71,9 @@ suite('Application Diagnostics - Jedi with Python 2.7 deprecated', () => { ); const service = new JediPython27NotSupportedDiagnosticService( - ({ + { get: () => ({}), - } as unknown) as IServiceContainer, + } as unknown as IServiceContainer, interpreterService, workspaceService, configurationService, @@ -95,9 +96,9 @@ suite('Application Diagnostics - Jedi with Python 2.7 deprecated', () => { ); const service = new JediPython27NotSupportedDiagnosticService( - ({ + { get: () => ({}), - } as unknown) as IServiceContainer, + } as unknown as IServiceContainer, interpreterService, workspaceService, configurationService, @@ -127,9 +128,9 @@ suite('Application Diagnostics - Jedi with Python 2.7 deprecated', () => { ); const service = new JediPython27NotSupportedDiagnosticService( - ({ + { get: () => ({}), - } as unknown) as IServiceContainer, + } as unknown as IServiceContainer, interpreterService, workspaceService, configurationService, @@ -161,9 +162,9 @@ suite('Application Diagnostics - Jedi with Python 2.7 deprecated', () => { ); const service = new JediPython27NotSupportedDiagnosticService( - ({ + { get: () => ({}), - } as unknown) as IServiceContainer, + } as unknown as IServiceContainer, interpreterService, workspaceService, configurationService, @@ -195,9 +196,9 @@ suite('Application Diagnostics - Jedi with Python 2.7 deprecated', () => { ); const service = new JediPython27NotSupportedDiagnosticService( - ({ + { get: () => ({}), - } as unknown) as IServiceContainer, + } as unknown as IServiceContainer, interpreterService, workspaceService, configurationService, @@ -227,9 +228,9 @@ suite('Application Diagnostics - Jedi with Python 2.7 deprecated', () => { ); const service = new JediPython27NotSupportedDiagnosticService( - ({ + { get: () => ({}), - } as unknown) as IServiceContainer, + } as unknown as IServiceContainer, interpreterService, workspaceService, configurationService, @@ -265,10 +266,10 @@ suite('Application Diagnostics - Jedi with Python 2.7 deprecated', () => { } as IInterpreterService; setup(() => { - serviceContainer = ({ + serviceContainer = { get: (serviceIdentifier: symbol) => services[serviceIdentifier.toString()] as IWorkspaceService, tryGet: () => ({}), - } as unknown) as IServiceContainer; + } as unknown as IServiceContainer; workspaceService = new WorkspaceService(); services = { @@ -279,9 +280,9 @@ suite('Application Diagnostics - Jedi with Python 2.7 deprecated', () => { updateSettingStub = sinon.stub(ConfigurationService.prototype, 'updateSetting'); const getSettingsStub = sinon.stub(ConfigurationService.prototype, 'getSettings'); - getSettingsStub.returns(({ + getSettingsStub.returns({ getSettings: () => ({ languageServer: LanguageServerType.Jedi }), - } as unknown) as IPythonSettings); + } as unknown as IPythonSettings); }); teardown(() => { @@ -297,9 +298,9 @@ suite('Application Diagnostics - Jedi with Python 2.7 deprecated', () => { const configurationService = new ConfigurationService(serviceContainer); const service = new JediPython27NotSupportedDiagnosticService( - ({ + { get: () => ({}), - } as unknown) as IServiceContainer, + } as unknown as IServiceContainer, interpreterService, workspaceService, configurationService, @@ -328,9 +329,9 @@ suite('Application Diagnostics - Jedi with Python 2.7 deprecated', () => { const configurationService = new ConfigurationService(serviceContainer); const service = new JediPython27NotSupportedDiagnosticService( - ({ + { get: () => ({}), - } as unknown) as IServiceContainer, + } as unknown as IServiceContainer, interpreterService, workspaceService, configurationService, @@ -359,9 +360,9 @@ suite('Application Diagnostics - Jedi with Python 2.7 deprecated', () => { const configurationService = new ConfigurationService(serviceContainer); const service = new JediPython27NotSupportedDiagnosticService( - ({ + { get: () => ({}), - } as unknown) as IServiceContainer, + } as unknown as IServiceContainer, interpreterService, workspaceService, configurationService, @@ -384,9 +385,9 @@ suite('Application Diagnostics - Jedi with Python 2.7 deprecated', () => { const configurationService = new ConfigurationService(serviceContainer); const service = new JediPython27NotSupportedDiagnosticService( - ({ + { get: () => ({}), - } as unknown) as IServiceContainer, + } as unknown as IServiceContainer, interpreterService, workspaceService, configurationService, @@ -465,9 +466,9 @@ suite('Application Diagnostics - Jedi with Python 2.7 deprecated', () => { test('Handling a diagnostic that should be ignored does not display a prompt', async () => { const diagnosticHandlerService = new DiagnosticCommandPromptHandlerService(serviceContainer); - services['Symbol(IDiagnosticFilterService)'] = ({ + services['Symbol(IDiagnosticFilterService)'] = { shouldIgnoreDiagnostic: async () => Promise.resolve(true), - } as unknown) as IDiagnosticFilterService; + } as unknown as IDiagnosticFilterService; const service = new TestJediPython27NotSupportedDiagnosticService( serviceContainer, @@ -487,9 +488,9 @@ suite('Application Diagnostics - Jedi with Python 2.7 deprecated', () => { const diagnosticHandlerService = new DiagnosticCommandPromptHandlerService(serviceContainer); const configurationService = new ConfigurationService(serviceContainer); - services['Symbol(IDiagnosticFilterService)'] = ({ + services['Symbol(IDiagnosticFilterService)'] = { shouldIgnoreDiagnostic: () => Promise.resolve(false), - } as unknown) as IDiagnosticFilterService; + } as unknown as IDiagnosticFilterService; const service = new TestJediPython27NotSupportedDiagnosticService( serviceContainer, diff --git a/src/test/application/diagnostics/checks/macPythonInterpreter.unit.test.ts b/src/test/application/diagnostics/checks/macPythonInterpreter.unit.test.ts index ba2436d0ffeb..170ad4c70040 100644 --- a/src/test/application/diagnostics/checks/macPythonInterpreter.unit.test.ts +++ b/src/test/application/diagnostics/checks/macPythonInterpreter.unit.test.ts @@ -181,8 +181,8 @@ suite('Application Diagnostics - Checks Mac Python Interpreter', () => { DiagnosticCodes.MacInterpreterSelected, undefined, ); - const cmd = ({} as any) as IDiagnosticCommand; - const cmdIgnore = ({} as any) as IDiagnosticCommand; + const cmd = {} as any as IDiagnosticCommand; + const cmdIgnore = {} as any as IDiagnosticCommand; let messagePrompt: MessageCommandPrompt | undefined; messageHandler .setup((i) => i.handle(typemoq.It.isValue(diagnostic), typemoq.It.isAny())) diff --git a/src/test/application/diagnostics/checks/pythonInterpreter.unit.test.ts b/src/test/application/diagnostics/checks/pythonInterpreter.unit.test.ts index 2eecf052e433..4b56649f104b 100644 --- a/src/test/application/diagnostics/checks/pythonInterpreter.unit.test.ts +++ b/src/test/application/diagnostics/checks/pythonInterpreter.unit.test.ts @@ -149,7 +149,7 @@ suite('Application Diagnostics - Checks Python Interpreter', () => { interpreterService.setup((i) => i.hasInterpreters()).returns(() => Promise.resolve(true)); interpreterService .setup((i) => i.getActiveInterpreter(typemoq.It.isAny())) - .returns(() => Promise.resolve(({ path: 'interpreterpath' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: 'interpreterpath' } as unknown as PythonEnvironment)); const result2 = await triggerFunction!(undefined); expect(result2).to.equal(true); }); @@ -349,7 +349,7 @@ suite('Application Diagnostics - Checks Python Interpreter', () => { test('Handling comspec diagnostic should launch expected browser link', async () => { const diagnostic = new DefaultShellDiagnostic(DiagnosticCodes.InvalidComspecDiagnostic, undefined); - const cmd = ({} as any) as IDiagnosticCommand; + const cmd = {} as any as IDiagnosticCommand; let messagePrompt: MessageCommandPrompt | undefined; messageHandler .setup((i) => i.handle(typemoq.It.isValue(diagnostic), typemoq.It.isAny())) @@ -384,7 +384,7 @@ suite('Application Diagnostics - Checks Python Interpreter', () => { test('Handling incomplete path diagnostic should launch expected browser link', async () => { const diagnostic = new DefaultShellDiagnostic(DiagnosticCodes.IncompletePathVarDiagnostic, undefined); - const cmd = ({} as any) as IDiagnosticCommand; + const cmd = {} as any as IDiagnosticCommand; let messagePrompt: MessageCommandPrompt | undefined; messageHandler .setup((i) => i.handle(typemoq.It.isValue(diagnostic), typemoq.It.isAny())) @@ -419,7 +419,7 @@ suite('Application Diagnostics - Checks Python Interpreter', () => { test('Handling default shell error diagnostic should launch expected browser link', async () => { const diagnostic = new DefaultShellDiagnostic(DiagnosticCodes.DefaultShellErrorDiagnostic, undefined); - const cmd = ({} as any) as IDiagnosticCommand; + const cmd = {} as any as IDiagnosticCommand; let messagePrompt: MessageCommandPrompt | undefined; messageHandler .setup((i) => i.handle(typemoq.It.isValue(diagnostic), typemoq.It.isAny())) @@ -458,7 +458,7 @@ suite('Application Diagnostics - Checks Python Interpreter', () => { undefined, workspaceService.object, ); - const cmd = ({} as any) as IDiagnosticCommand; + const cmd = {} as any as IDiagnosticCommand; let messagePrompt: MessageCommandPrompt | undefined; messageHandler .setup((i) => i.handle(typemoq.It.isValue(diagnostic), typemoq.It.isAny())) @@ -498,7 +498,7 @@ suite('Application Diagnostics - Checks Python Interpreter', () => { undefined, workspaceService.object, ); - const cmd = ({} as any) as IDiagnosticCommand; + const cmd = {} as any as IDiagnosticCommand; let messagePrompt: MessageCommandPrompt | undefined; messageHandler .setup((i) => i.handle(typemoq.It.isValue(diagnostic), typemoq.It.isAny())) @@ -530,7 +530,7 @@ suite('Application Diagnostics - Checks Python Interpreter', () => { }); test('Handling an empty diagnostic should not show a message nor return a command', async () => { const diagnostics: IDiagnostic[] = []; - const cmd = ({} as any) as IDiagnosticCommand; + const cmd = {} as any as IDiagnosticCommand; messageHandler .setup((i) => i.handle(typemoq.It.isAny(), typemoq.It.isAny())) @@ -560,10 +560,10 @@ suite('Application Diagnostics - Checks Python Interpreter', () => { undefined, workspaceService.object, ); - const cmd = ({} as any) as IDiagnosticCommand; - const diagnosticServiceMock = (typemoq.Mock.ofInstance(diagnosticService) as any) as typemoq.IMock< - InvalidPythonInterpreterService - >; + const cmd = {} as any as IDiagnosticCommand; + const diagnosticServiceMock = typemoq.Mock.ofInstance( + diagnosticService, + ) as any as typemoq.IMock; diagnosticServiceMock.setup((f) => f.canHandle(typemoq.It.isAny())).returns(() => Promise.resolve(false)); messageHandler diff --git a/src/test/common.ts b/src/test/common.ts index 00de8fd3f4a6..a7d600af2884 100644 --- a/src/test/common.ts +++ b/src/test/common.ts @@ -109,13 +109,13 @@ export const resetGlobalInterpreterPathSetting = async () => retryAsync(restoreG async function restoreGlobalInterpreterPathSetting(): Promise { const vscode = require('vscode') as typeof import('vscode'); - const pythonConfig = vscode.workspace.getConfiguration('python', (null as any) as Uri); + const pythonConfig = vscode.workspace.getConfiguration('python', null as any as Uri); await pythonConfig.update('defaultInterpreterPath', undefined, true); await disposePythonSettings(); } async function setGlobalPathToInterpreter(pythonPath?: string): Promise { const vscode = require('vscode') as typeof import('vscode'); - const pythonConfig = vscode.workspace.getConfiguration('python', (null as any) as Uri); + const pythonConfig = vscode.workspace.getConfiguration('python', null as any as Uri); await pythonConfig.update('defaultInterpreterPath', pythonPath, true); await disposePythonSettings(); } @@ -200,7 +200,7 @@ async function setPythonPathInWorkspace( } async function restoreGlobalPythonPathSetting(): Promise { const vscode = require('vscode') as typeof import('vscode'); - const pythonConfig = vscode.workspace.getConfiguration('python', (null as any) as Uri); + const pythonConfig = vscode.workspace.getConfiguration('python', null as any as Uri); await Promise.all([ pythonConfig.update('defaultInterpreterPath', undefined, true), pythonConfig.update('defaultInterpreterPath', undefined, true), @@ -462,6 +462,7 @@ export async function waitForCondition( const timeout = setTimeout(() => { clearTimeout(timeout); + // eslint-disable-next-line @typescript-eslint/no-use-before-define clearTimeout(timer); reject(new Error(errorMessage)); }, timeoutMs); diff --git a/src/test/common/application/commands/createNewFileCommand.unit.test.ts b/src/test/common/application/commands/createNewFileCommand.unit.test.ts index c50c7f729148..75f3c94ea94a 100644 --- a/src/test/common/application/commands/createNewFileCommand.unit.test.ts +++ b/src/test/common/application/commands/createNewFileCommand.unit.test.ts @@ -28,7 +28,7 @@ suite('Create New Python File Commmand', () => { [], ); when(workspaceService.openTextDocument(deepEqual({ language: 'python' }))).thenReturn( - Promise.resolve(({} as unknown) as TextDocument), + Promise.resolve({} as unknown as TextDocument), ); await createNewFileCommandHandler.activate(); }); diff --git a/src/test/common/application/commands/reportIssueCommand.unit.test.ts b/src/test/common/application/commands/reportIssueCommand.unit.test.ts index b1884fa83c21..6e4adc85501e 100644 --- a/src/test/common/application/commands/reportIssueCommand.unit.test.ts +++ b/src/test/common/application/commands/reportIssueCommand.unit.test.ts @@ -56,10 +56,10 @@ suite('Report Issue Command', () => { languageServer: LanguageServerType.Node, }), ); - const interpreter = ({ + const interpreter = { envType: EnvironmentType.Venv, version: { raw: '3.9.0' }, - } as unknown) as PythonEnvironment; + } as unknown as PythonEnvironment; when(interpreterService.getActiveInterpreter()).thenResolve(interpreter); when(configurationService.getSettings()).thenReturn({ experiments: { diff --git a/src/test/common/configSettings.test.ts b/src/test/common/configSettings.test.ts index a8b4961f037c..0184ac817795 100644 --- a/src/test/common/configSettings.test.ts +++ b/src/test/common/configSettings.test.ts @@ -15,7 +15,7 @@ suite('Configuration Settings', () => { test('Check Values', (done) => { const systemVariables: SystemVariables = new SystemVariables(undefined, workspaceRoot); - const pythonConfig = vscode.workspace.getConfiguration('python', (null as any) as vscode.Uri); + const pythonConfig = vscode.workspace.getConfiguration('python', null as any as vscode.Uri); const pythonSettings = getExtensionSettings(vscode.Uri.file(workspaceRoot)); Object.keys(pythonSettings).forEach((key) => { let settingValue = pythonConfig.get(key, 'Not a config'); diff --git a/src/test/common/experiments/service.unit.test.ts b/src/test/common/experiments/service.unit.test.ts index 661efeaa8bb9..219ba26d2a9e 100644 --- a/src/test/common/experiments/service.unit.test.ts +++ b/src/test/common/experiments/service.unit.test.ts @@ -181,9 +181,9 @@ suite('Experimentation service', () => { }); getTreatmentVariable = sinon.stub().returns(true); - sinon.stub(tasClient, 'getExperimentationService').returns(({ + sinon.stub(tasClient, 'getExperimentationService').returns({ getTreatmentVariable, - } as unknown) as expService.IExperimentationService); + } as unknown as expService.IExperimentationService); configureApplicationEnvironment('stable', extensionVersion); }); @@ -219,9 +219,9 @@ suite('Experimentation service', () => { // Control group returns false. getTreatmentVariable = sinon.stub().returns(false); - sinon.stub(tasClient, 'getExperimentationService').returns(({ + sinon.stub(tasClient, 'getExperimentationService').returns({ getTreatmentVariable, - } as unknown) as expService.IExperimentationService); + } as unknown as expService.IExperimentationService); configureApplicationEnvironment('stable', extensionVersion); @@ -365,9 +365,9 @@ suite('Experimentation service', () => { setup(() => { getTreatmentVariableStub = sinon.stub().returns(Promise.resolve('value')); - sinon.stub(tasClient, 'getExperimentationService').returns(({ + sinon.stub(tasClient, 'getExperimentationService').returns({ getTreatmentVariable: getTreatmentVariableStub, - } as unknown) as expService.IExperimentationService); + } as unknown as expService.IExperimentationService); configureApplicationEnvironment('stable', extensionVersion); }); diff --git a/src/test/common/installer/pipInstaller.unit.test.ts b/src/test/common/installer/pipInstaller.unit.test.ts index 7b7af714f7f7..4bbac0017ea4 100644 --- a/src/test/common/installer/pipInstaller.unit.test.ts +++ b/src/test/common/installer/pipInstaller.unit.test.ts @@ -30,7 +30,7 @@ suite('xPip installer', async () => { .returns(() => interpreterService.object); interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve((interpreter as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve(interpreter as unknown as PythonEnvironment)); serviceContainer .setup((c) => c.get(TypeMoq.It.isValue(IPythonExecutionFactory))) .returns(() => pythonExecutionFactory.object); @@ -88,7 +88,7 @@ suite('xPip installer', async () => { interpreterService.reset(); interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve((condaInterpreter as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve(condaInterpreter as unknown as PythonEnvironment)); const result = await pipInstaller.isSupported(resource); expect(result).to.equal(false); }); diff --git a/src/test/common/platform/filesystem.unit.test.ts b/src/test/common/platform/filesystem.unit.test.ts index f012cb9fb27e..caaf7b913521 100644 --- a/src/test/common/platform/filesystem.unit.test.ts +++ b/src/test/common/platform/filesystem.unit.test.ts @@ -238,7 +238,7 @@ suite('Raw FileSystem', () => { raw.setup((r) => r.dirname(tgt)) // Provide the target's parent. .returns(() => 'x/y'); raw.setup((r) => r.stat(Uri('x/y'))) // The parent dir exists. - .returns(() => Promise.resolve((undefined as unknown) as FileStat)); + .returns(() => Promise.resolve(undefined as unknown as FileStat)); raw.setup((r) => r.rename(Uri(src), Uri(tgt), { overwrite: false })) // expect the specific filename .returns(() => Promise.resolve()); @@ -253,12 +253,12 @@ suite('Raw FileSystem', () => { raw.setup((r) => r.dirname(tgt)) // Provide the target's parent. .returns(() => 'x/y'); raw.setup((r) => r.stat(Uri('x/y'))) // The parent dir exists. - .returns(() => Promise.resolve((undefined as unknown) as FileStat)); + .returns(() => Promise.resolve(undefined as unknown as FileStat)); const err = vscode.FileSystemError.FileExists('...'); raw.setup((r) => r.rename(Uri(src), Uri(tgt), { overwrite: false })) // expect the specific filename .returns(() => Promise.reject(err)); raw.setup((r) => r.stat(Uri(tgt))) // It's a file. - .returns(() => Promise.resolve(({ type: FileType.File } as unknown) as FileStat)); + .returns(() => Promise.resolve({ type: FileType.File } as unknown as FileStat)); raw.setup((r) => r.rename(Uri(src), Uri(tgt), { overwrite: true })) // expect the specific filename .returns(() => Promise.resolve()); @@ -273,7 +273,7 @@ suite('Raw FileSystem', () => { raw.setup((r) => r.dirname(tgt)) // Provide the target's parent. .returns(() => 'x/y'); raw.setup((r) => r.stat(Uri('x/y'))) // The parent dir exists. - .returns(() => Promise.resolve((undefined as unknown) as FileStat)); + .returns(() => Promise.resolve(undefined as unknown as FileStat)); raw.setup((r) => r.rename(Uri(src), Uri(tgt), { overwrite: false })) // expect the specific filename .returns(() => Promise.resolve()); @@ -288,12 +288,12 @@ suite('Raw FileSystem', () => { raw.setup((r) => r.dirname(tgt)) // Provide the target's parent. .returns(() => 'x/y'); raw.setup((r) => r.stat(Uri('x/y'))) // The parent dir exists. - .returns(() => Promise.resolve((undefined as unknown) as FileStat)); + .returns(() => Promise.resolve(undefined as unknown as FileStat)); const err = vscode.FileSystemError.FileExists('...'); raw.setup((r) => r.rename(Uri(src), Uri(tgt), { overwrite: false })) // expect the specific filename .returns(() => Promise.reject(err)); raw.setup((r) => r.stat(Uri(tgt))) // It's a directory. - .returns(() => Promise.resolve(({ type: FileType.Directory } as unknown) as FileStat)); + .returns(() => Promise.resolve({ type: FileType.Directory } as unknown as FileStat)); const promise = filesystem.move(src, tgt); @@ -307,13 +307,13 @@ suite('Raw FileSystem', () => { raw.setup((r) => r.dirname(tgt)) // Provide the target's parent. .returns(() => 'x/y'); raw.setup((r) => r.stat(Uri('x/y'))) // The parent dir exists. - .returns(() => Promise.resolve((undefined as unknown) as FileStat)); + .returns(() => Promise.resolve(undefined as unknown as FileStat)); const err = vscode.FileSystemError.FileExists('...'); raw.setup((r) => r.rename(Uri(src), Uri(tgt), { overwrite: false })) // expect the specific filename .returns(() => Promise.reject(err)); raw.setup((r) => r.stat(Uri(tgt))) // It's a symlink. .returns(() => - Promise.resolve(({ type: FileType.SymbolicLink | FileType.Directory } as unknown) as FileStat), + Promise.resolve({ type: FileType.SymbolicLink | FileType.Directory } as unknown as FileStat), ); raw.setup((r) => r.rename(Uri(src), Uri(tgt), { overwrite: true })) // expect the specific filename .returns(() => Promise.resolve()); @@ -340,7 +340,7 @@ suite('Raw FileSystem', () => { raw.setup((r) => r.dirname(TypeMoq.It.isAny())) // Provide the target's parent. .returns(() => ''); raw.setup((r) => r.stat(TypeMoq.It.isAny())) // The parent dir exists. - .returns(() => Promise.resolve((undefined as unknown) as FileStat)); + .returns(() => Promise.resolve(undefined as unknown as FileStat)); const err = new Error('oops!'); raw.setup((r) => r.rename(TypeMoq.It.isAny(), TypeMoq.It.isAny(), { overwrite: false })) // We don't care about the filename. .throws(err); @@ -455,7 +455,7 @@ suite('Raw FileSystem', () => { raw.setup((r) => r.dirname(tgt)) // Provide the target's parent. .returns(() => 'x/y/z'); raw.setup((r) => r.stat(Uri('x/y/z'))) // The parent dir exists. - .returns(() => Promise.resolve((undefined as unknown) as FileStat)); + .returns(() => Promise.resolve(undefined as unknown as FileStat)); raw.setup((r) => r.copy(Uri(src), Uri(tgt), { overwrite: true })) // Expect the specific args. .returns(() => Promise.resolve()); @@ -481,7 +481,7 @@ suite('Raw FileSystem', () => { raw.setup((r) => r.dirname(TypeMoq.It.isAny())) // Provide the target's parent. .returns(() => ''); raw.setup((r) => r.stat(TypeMoq.It.isAny())) // The parent dir exists. - .returns(() => Promise.resolve((undefined as unknown) as FileStat)); + .returns(() => Promise.resolve(undefined as unknown as FileStat)); raw.setup((r) => r.copy(TypeMoq.It.isAny(), TypeMoq.It.isAny(), { overwrite: true })) // We don't care about the filename. .throws(new Error('file not found')); @@ -607,7 +607,7 @@ suite('Raw FileSystem', () => { test('wraps the low-level function', async () => { const dirname = 'x/y/z/spam'; raw.setup((r) => r.stat(Uri(dirname))) // The dir exists. - .returns(() => Promise.resolve((undefined as unknown) as FileStat)); + .returns(() => Promise.resolve(undefined as unknown as FileStat)); raw.setup((r) => r.delete(Uri(dirname), opts)) // Expect the specific dirname. .returns(() => Promise.resolve()); @@ -618,7 +618,7 @@ suite('Raw FileSystem', () => { test('fails if the low-level call fails', async () => { raw.setup((r) => r.stat(TypeMoq.It.isAny())) // The "file" exists. - .returns(() => Promise.resolve((undefined as unknown) as FileStat)); + .returns(() => Promise.resolve(undefined as unknown as FileStat)); raw.setup((r) => r.delete(TypeMoq.It.isAny(), opts)) // We don't care about the filename. .throws(new Error('file not found')); @@ -1300,7 +1300,7 @@ suite('FileSystemUtils', () => { const dirname = 'x/y/z/spam'; const filename = `${dirname}/___vscpTest___`; deps.setup((d) => d.stat(dirname)) // Success! - .returns(() => Promise.resolve((undefined as unknown) as FileStat)); + .returns(() => Promise.resolve(undefined as unknown as FileStat)); deps.setup((d) => d.writeText(filename, '')) // Success! .returns(() => Promise.resolve()); deps.setup((d) => d.rmfile(filename)) // Success! @@ -1319,7 +1319,7 @@ suite('FileSystemUtils', () => { (err as any).code = 'EACCES'; // errno deps.setup((d) => d.stat(dirname)) // Success! - .returns(() => Promise.resolve((undefined as unknown) as FileStat)); + .returns(() => Promise.resolve(undefined as unknown as FileStat)); deps.setup((d) => d.writeText(filename, '')) // not permitted .returns(() => Promise.reject(err)); @@ -1430,7 +1430,7 @@ suite('FileSystemUtils', () => { test('no matches (undefined)', async () => { const pattern = `x/y/z/spam.*`; deps.setup((d) => d.globFile(pattern, undefined)) // found none - .returns(() => Promise.resolve((undefined as unknown) as string[])); + .returns(() => Promise.resolve(undefined as unknown as string[])); const files = await utils.search(pattern); @@ -1443,7 +1443,7 @@ suite('FileSystemUtils', () => { test('file exists', async () => { const filename = 'x/y/z/spam.py'; deps.setup((d) => d.statSync(filename)) // The file exists. - .returns(() => (undefined as unknown) as FileStat); + .returns(() => undefined as unknown as FileStat); const exists = utils.fileExistsSync(filename); diff --git a/src/test/common/process/logger.unit.test.ts b/src/test/common/process/logger.unit.test.ts index f1421ea58b85..2aa86cbe7574 100644 --- a/src/test/common/process/logger.unit.test.ts +++ b/src/test/common/process/logger.unit.test.ts @@ -23,7 +23,7 @@ suite('ProcessLogger suite', () => { workspaceService = TypeMoq.Mock.ofType(); workspaceService .setup((w) => w.workspaceFolders) - .returns(() => [({ uri: { fsPath: path.join('path', 'to', 'workspace') } } as unknown) as WorkspaceFolder]); + .returns(() => [{ uri: { fsPath: path.join('path', 'to', 'workspace') } } as unknown as WorkspaceFolder]); logger = new ProcessLogger(workspaceService.object); }); diff --git a/src/test/common/process/pythonExecutionFactory.unit.test.ts b/src/test/common/process/pythonExecutionFactory.unit.test.ts index 0981c59e78bb..a5f01526fd7e 100644 --- a/src/test/common/process/pythonExecutionFactory.unit.test.ts +++ b/src/test/common/process/pythonExecutionFactory.unit.test.ts @@ -237,7 +237,7 @@ suite('Process - PythonExecutionFactory', () => { factory.create = async () => { createInvoked = true; // eslint-disable-next-line @typescript-eslint/no-explicit-any - return Promise.resolve((mockExecService as any) as IPythonExecutionService); + return Promise.resolve(mockExecService as any as IPythonExecutionService); }; const service = await verifyCreateActivated(factory, activationHelper, resource, interpreter); @@ -256,7 +256,7 @@ suite('Process - PythonExecutionFactory', () => { factory.create = async () => { createInvoked = true; // eslint-disable-next-line @typescript-eslint/no-explicit-any - return Promise.resolve((mockExecService as any) as IPythonExecutionService); + return Promise.resolve(mockExecService as any as IPythonExecutionService); }; const service = await verifyCreateActivated(factory, activationHelper, resource, interpreter); @@ -269,7 +269,7 @@ suite('Process - PythonExecutionFactory', () => { factory.create = async () => { createInvoked = true; // eslint-disable-next-line @typescript-eslint/no-explicit-any - return Promise.resolve((mockExecService as any) as IPythonExecutionService); + return Promise.resolve(mockExecService as any as IPythonExecutionService); }; const pythonSettings = mock(PythonSettings); @@ -359,7 +359,7 @@ suite('Process - PythonExecutionFactory', () => { factory.create = async () => { createInvoked = true; // eslint-disable-next-line @typescript-eslint/no-explicit-any - return Promise.resolve((mockExecService as any) as IPythonExecutionService); + return Promise.resolve(mockExecService as any as IPythonExecutionService); }; const pythonSettings = mock(PythonSettings); diff --git a/src/test/common/socketStream.test.ts b/src/test/common/socketStream.test.ts index 35420e4a614c..19298b132bf1 100644 --- a/src/test/common/socketStream.test.ts +++ b/src/test/common/socketStream.test.ts @@ -42,7 +42,7 @@ suite('SocketStream', () => { const byteValue = buffer[0]; const socket = new MockSocket(); - const stream = new SocketStream((socket as any) as net.Socket, buffer); + const stream = new SocketStream(socket as any as net.Socket, buffer); assert.strictEqual(stream.ReadByte(), byteValue); done(); @@ -52,7 +52,7 @@ suite('SocketStream', () => { const socket = new MockSocket(); const buffer = uint64be.encode(num); - const stream = new SocketStream((socket as any) as net.Socket, buffer); + const stream = new SocketStream(socket as any as net.Socket, buffer); assert.strictEqual(stream.ReadInt32(), num); done(); @@ -62,7 +62,7 @@ suite('SocketStream', () => { const socket = new MockSocket(); const buffer = uint64be.encode(num); - const stream = new SocketStream((socket as any) as net.Socket, buffer); + const stream = new SocketStream(socket as any as net.Socket, buffer); assert.strictEqual(stream.ReadInt64(), num); done(); @@ -72,7 +72,7 @@ suite('SocketStream', () => { const socket = new MockSocket(); const buffer = Buffer.concat([Buffer.from('A'), uint64be.encode(message.length), Buffer.from(message)]); - const stream = new SocketStream((socket as any) as net.Socket, buffer); + const stream = new SocketStream(socket as any as net.Socket, buffer); assert.strictEqual(stream.ReadString(), message); done(); @@ -86,7 +86,7 @@ suite('SocketStream', () => { stringBuffer, ]); - const stream = new SocketStream((socket as any) as net.Socket, buffer); + const stream = new SocketStream(socket as any as net.Socket, buffer); assert.strictEqual(stream.ReadString(), message); done(); @@ -100,7 +100,7 @@ suite('SocketStream', () => { const partOfSecondMessage = Buffer.concat([Buffer.from('A'), uint64be.encode(message.length)]); buffer = Buffer.concat([buffer, partOfSecondMessage]); - const stream = new SocketStream((socket as any) as net.Socket, buffer); + const stream = new SocketStream(socket as any as net.Socket, buffer); stream.BeginTransaction(); assert.strictEqual(stream.ReadString(), message, 'First message not read properly'); @@ -123,7 +123,7 @@ suite('SocketStream', () => { const partOfSecondMessage = Buffer.concat([Buffer.from('A'), uint64be.encode(message.length)]); buffer = Buffer.concat([buffer, partOfSecondMessage]); - const stream = new SocketStream((socket as any) as net.Socket, buffer); + const stream = new SocketStream(socket as any as net.Socket, buffer); stream.BeginTransaction(); assert.strictEqual(stream.ReadString(), message, 'First message not read properly'); @@ -139,7 +139,7 @@ suite('SocketStream', () => { const buffer = Buffer.from(''); const socket = new MockSocket(); - const stream = new SocketStream((socket as any) as net.Socket, buffer); + const stream = new SocketStream(socket as any as net.Socket, buffer); stream.Write(Buffer.from(message)); assert.strictEqual(socket.dataWritten, message); @@ -150,7 +150,7 @@ suite('SocketStream', () => { const buffer = Buffer.from(''); const socket = new MockSocket(); - const stream = new SocketStream((socket as any) as net.Socket, buffer); + const stream = new SocketStream(socket as any as net.Socket, buffer); stream.WriteInt32(num); assert.strictEqual(uint64be.decode(socket.rawDataWritten), num); @@ -161,7 +161,7 @@ suite('SocketStream', () => { const buffer = Buffer.from(''); const socket = new MockSocket(); - const stream = new SocketStream((socket as any) as net.Socket, buffer); + const stream = new SocketStream(socket as any as net.Socket, buffer); stream.WriteInt64(num); assert.strictEqual(uint64be.decode(socket.rawDataWritten), num); @@ -172,7 +172,7 @@ suite('SocketStream', () => { const buffer = Buffer.from(''); const socket = new MockSocket(); - const stream = new SocketStream((socket as any) as net.Socket, buffer); + const stream = new SocketStream(socket as any as net.Socket, buffer); stream.WriteString(message); assert.strictEqual(socket.dataWritten, message); @@ -183,7 +183,7 @@ suite('SocketStream', () => { const buffer = Buffer.from(''); const socket = new MockSocket(); - const stream = new SocketStream((socket as any) as net.Socket, buffer); + const stream = new SocketStream(socket as any as net.Socket, buffer); stream.WriteString(message); assert.strictEqual(socket.dataWritten, message); diff --git a/src/test/common/terminals/activation.bash.unit.test.ts b/src/test/common/terminals/activation.bash.unit.test.ts index cd057e7be3e5..035ed5a4ab33 100644 --- a/src/test/common/terminals/activation.bash.unit.test.ts +++ b/src/test/common/terminals/activation.bash.unit.test.ts @@ -45,7 +45,7 @@ suite('Terminal Environment Activation (bash)', () => { interpreterService = TypeMoq.Mock.ofType(); interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: pythonPath } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: pythonPath } as unknown as PythonEnvironment)); serviceContainer .setup((c) => c.get(IInterpreterService)) .returns(() => interpreterService.object); diff --git a/src/test/common/terminals/activation.commandPrompt.unit.test.ts b/src/test/common/terminals/activation.commandPrompt.unit.test.ts index ed21d7625dab..2cedbd06e1a0 100644 --- a/src/test/common/terminals/activation.commandPrompt.unit.test.ts +++ b/src/test/common/terminals/activation.commandPrompt.unit.test.ts @@ -39,7 +39,7 @@ suite('Terminal Environment Activation (cmd/powershell)', () => { interpreterService = TypeMoq.Mock.ofType(); interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: pythonPath } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: pythonPath } as unknown as PythonEnvironment)); serviceContainer .setup((c) => c.get(IInterpreterService)) .returns(() => interpreterService.object); @@ -89,7 +89,7 @@ suite('Terminal Environment Activation (cmd/powershell)', () => { interpreterService = TypeMoq.Mock.ofType(); interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: pythonPath } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: pythonPath } as unknown as PythonEnvironment)); serviceContainer.setup((c) => c.get(IInterpreterService)).returns(() => interpreterService.object); serviceContainer.setup((c) => c.get(IFileSystem)).returns(() => fileSystem.object); serviceContainer.setup((c) => c.get(IPlatformService)).returns(() => platform.object); @@ -181,7 +181,7 @@ suite('Terminal Environment Activation (cmd/powershell)', () => { interpreterService = TypeMoq.Mock.ofType(); interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: pythonPath } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: pythonPath } as unknown as PythonEnvironment)); serviceContainer.setup((c) => c.get(IInterpreterService)).returns(() => interpreterService.object); }); diff --git a/src/test/common/terminals/activation.nushell.unit.test.ts b/src/test/common/terminals/activation.nushell.unit.test.ts index bf748bc7c053..b146cedfa02d 100644 --- a/src/test/common/terminals/activation.nushell.unit.test.ts +++ b/src/test/common/terminals/activation.nushell.unit.test.ts @@ -29,7 +29,7 @@ suite('Terminal Environment Activation (nushell)', () => { interpreterService = TypeMoq.Mock.ofType(); interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: pythonPath } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: pythonPath } as unknown as PythonEnvironment)); serviceContainer.setup((c) => c.get(IInterpreterService)).returns(() => interpreterService.object); }); diff --git a/src/test/common/terminals/activation.unit.test.ts b/src/test/common/terminals/activation.unit.test.ts index 49ada1c06b11..65e6dd67b475 100644 --- a/src/test/common/terminals/activation.unit.test.ts +++ b/src/test/common/terminals/activation.unit.test.ts @@ -25,7 +25,7 @@ suite('Terminal Auto Activation', () => { let terminal: Terminal; setup(() => { - terminal = ({ + terminal = { dispose: noop, hide: noop, name: 'Python', @@ -34,7 +34,7 @@ suite('Terminal Auto Activation', () => { sendText: noop, show: noop, exitStatus: { code: 0 }, - } as unknown) as Terminal; + } as unknown as Terminal; terminalManager = mock(TerminalManager); activator = mock(TerminalActivator); activeResourceService = mock(ActiveResourceService); @@ -68,7 +68,7 @@ suite('Terminal Auto Activation', () => { verify(activator.activateEnvironmentInTerminal(terminal, anything())).once(); }); test('New Terminals should not be activated if hidden from user', async () => { - terminal = ({ + terminal = { dispose: noop, hide: noop, name: 'Python', @@ -77,7 +77,7 @@ suite('Terminal Auto Activation', () => { sendText: noop, show: noop, exitStatus: { code: 0 }, - } as unknown) as Terminal; + } as unknown as Terminal; type EventHandler = (e: Terminal) => void; let handler: undefined | EventHandler; const handlerDisposable = TypeMoq.Mock.ofType(); @@ -98,7 +98,7 @@ suite('Terminal Auto Activation', () => { verify(activator.activateEnvironmentInTerminal(terminal, anything())).never(); }); test('New Terminals should not be activated if auto activation is to be disabled', async () => { - terminal = ({ + terminal = { dispose: noop, hide: noop, name: 'Python', @@ -107,7 +107,7 @@ suite('Terminal Auto Activation', () => { sendText: noop, show: noop, exitStatus: { code: 0 }, - } as unknown) as Terminal; + } as unknown as Terminal; type EventHandler = (e: Terminal) => void; let handler: undefined | EventHandler; const handlerDisposable = TypeMoq.Mock.ofType(); diff --git a/src/test/common/terminals/activator/base.unit.test.ts b/src/test/common/terminals/activator/base.unit.test.ts index fdfe9dcee579..4acb7d6ad420 100644 --- a/src/test/common/terminals/activator/base.unit.test.ts +++ b/src/test/common/terminals/activator/base.unit.test.ts @@ -16,12 +16,12 @@ suite('Terminal Base Activator', () => { setup(() => { helper = TypeMoq.Mock.ofType(); - activator = (new (class extends BaseTerminalActivator { + activator = new (class extends BaseTerminalActivator { public waitForCommandToProcess() { noop(); return Promise.resolve(); } - })(helper.object) as any) as ITerminalActivator; + })(helper.object) as any as ITerminalActivator; }); [ { commandCount: 1, preserveFocus: false }, diff --git a/src/test/common/terminals/activator/index.unit.test.ts b/src/test/common/terminals/activator/index.unit.test.ts index 6a50901bc99d..57b7f2fd843a 100644 --- a/src/test/common/terminals/activator/index.unit.test.ts +++ b/src/test/common/terminals/activator/index.unit.test.ts @@ -43,9 +43,9 @@ suite('Terminal Activator', () => { configService .setup((c) => c.getSettings(TypeMoq.It.isAny())) .returns(() => { - return ({ + return { terminal: terminalSettings.object, - } as unknown) as IPythonSettings; + } as unknown as IPythonSettings; }); activator = new (class extends TerminalActivator { protected initialize() { diff --git a/src/test/common/terminals/helper.unit.test.ts b/src/test/common/terminals/helper.unit.test.ts index 0d130b573408..9b264c72c822 100644 --- a/src/test/common/terminals/helper.unit.test.ts +++ b/src/test/common/terminals/helper.unit.test.ts @@ -250,7 +250,7 @@ suite('Terminal Service helpers', () => { when(pipenvActivationProvider.isShellSupported(anything())).thenReturn(false); const cmd = await helper.getEnvironmentActivationCommands( - ('someShell' as any) as TerminalShellType, + 'someShell' as any as TerminalShellType, resource, ); diff --git a/src/test/common/terminals/service.unit.test.ts b/src/test/common/terminals/service.unit.test.ts index 63a1cd544940..0c37635dc8d0 100644 --- a/src/test/common/terminals/service.unit.test.ts +++ b/src/test/common/terminals/service.unit.test.ts @@ -105,7 +105,7 @@ suite('Terminal Service', () => { interpreterService = TypeMoq.Mock.ofType(); interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: 'ps' } as unknown as PythonEnvironment)); options = TypeMoq.Mock.ofType(); options.setup((o) => o.resource).returns(() => Uri.parse('a')); diff --git a/src/test/common/terminals/shellDetectors/shellDetectors.unit.test.ts b/src/test/common/terminals/shellDetectors/shellDetectors.unit.test.ts index e58e455ea7eb..c53820f1713d 100644 --- a/src/test/common/terminals/shellDetectors/shellDetectors.unit.test.ts +++ b/src/test/common/terminals/shellDetectors/shellDetectors.unit.test.ts @@ -103,9 +103,9 @@ suite('Shell Detectors', () => { shellPathsAndIdentification.forEach((shellType, shellPath) => { when(appEnv.shell).thenReturn('defaultshellPath'); expect( - shellDetector.identify(telemetryProperties, ({ + shellDetector.identify(telemetryProperties, { creationOptions: { shellPath }, - } as unknown) as Terminal), + } as unknown as Terminal), ).to.equal(shellType, `Incorrect Shell Type from identifyShellByTerminalName, for path '${shellPath}'`); }); }); diff --git a/src/test/common/utils/version.unit.test.ts b/src/test/common/utils/version.unit.test.ts index 3541b9b82926..30cd8b57d9f2 100644 --- a/src/test/common/utils/version.unit.test.ts +++ b/src/test/common/utils/version.unit.test.ts @@ -35,13 +35,13 @@ function ver( micro = -1; } const info = { - major: (major as unknown) as number, - minor: (minor as unknown) as number, - micro: (micro as unknown) as number, + major: major as unknown as number, + minor: minor as unknown as number, + micro: micro as unknown as number, raw: undefined, }; if (unnormalized !== undefined) { - ((info as unknown) as any).unnormalized = unnormalized; + (info as unknown as any).unnormalized = unnormalized; } return info; } @@ -143,7 +143,7 @@ suite('common utils - normalizeVersionInfo', () => { const info = ver(1, 2, 3); info.raw = '1.2.3'; - ((info as unknown) as any).unnormalized = unnorm('', '', ''); + (info as unknown as any).unnormalized = unnorm('', '', ''); const expected = info; const normalized = normalizeVersionInfo(info); @@ -188,7 +188,7 @@ suite('common utils - normalizeVersionInfo', () => { ].forEach((data) => { const [info, expected] = data; - ((expected as unknown) as any).unnormalized = unnorm('', '', ''); + (expected as unknown as any).unnormalized = unnorm('', '', ''); expected.raw = ''; test(`[${info.major}, ${info.minor}, ${info.micro}]`, () => { const normalized = normalizeVersionInfo(info); @@ -199,16 +199,18 @@ suite('common utils - normalizeVersionInfo', () => { }); suite('partially "invalid"', () => { - ([ - [ver(undefined, 4, 5), unnorm('missing', '', '')], - [ver(3, null, 5), unnorm('', 'missing', '')], - [ver(3, 4, NaN), unnorm('', '', 'missing')], - [ver(3, 4, ''), unnorm('', '', 'string not numeric')], - [ver(3, 4, ' '), unnorm('', '', 'string not numeric')], - [ver(3, 4, 'foo'), unnorm('', '', 'string not numeric')], - [ver(3, 4, {}), unnorm('', '', 'unsupported type')], - [ver(3, 4, []), unnorm('', '', 'unsupported type')], - ] as [VersionInfo, Unnormalized][]).forEach((data) => { + ( + [ + [ver(undefined, 4, 5), unnorm('missing', '', '')], + [ver(3, null, 5), unnorm('', 'missing', '')], + [ver(3, 4, NaN), unnorm('', '', 'missing')], + [ver(3, 4, ''), unnorm('', '', 'string not numeric')], + [ver(3, 4, ' '), unnorm('', '', 'string not numeric')], + [ver(3, 4, 'foo'), unnorm('', '', 'string not numeric')], + [ver(3, 4, {}), unnorm('', '', 'unsupported type')], + [ver(3, 4, []), unnorm('', '', 'unsupported type')], + ] as [VersionInfo, Unnormalized][] + ).forEach((data) => { const [info, unnormalized] = data; const expected = { ...info }; if (info.major !== 3) { @@ -219,7 +221,7 @@ suite('common utils - normalizeVersionInfo', () => { expected.micro = -1; } - ((expected as unknown) as any).unnormalized = unnormalized; + (expected as unknown as any).unnormalized = unnormalized; expected.raw = ''; test(`[${info.major}, ${info.minor}, ${info.micro}]`, () => { const normalized = normalizeVersionInfo(info); @@ -310,28 +312,30 @@ suite('common utils - parseVersionInfo', () => { }); suite('valid versions', () => { - ([ - // plain - ...VERSIONS.map(([v, s]) => [s, { version: v, before: '', after: '' }]), - ['02.7', res(2, 7, -1, '', '')], - ['2.07', res(2, 7, -1, '', '')], - ['2.7.01', res(2, 7, 1, '', '')], - // with before/after - [' 2.7.9 ', res(2, 7, 9, ' ', ' ')], - ['2.7.9-3.2.7', res(2, 7, 9, '', '-3.2.7')], - ['python2.7.exe', res(2, 7, -1, 'python', '.exe')], - ['1.2.3.4.5-x2.2', res(1, 2, 3, '', '.4.5-x2.2')], - ['3.8.1a2', res(3, 8, 1, '', 'a2')], - ['3.8.1-alpha2', res(3, 8, 1, '', '-alpha2')], + ( [ - '3.7.5 (default, Nov 7 2019, 10:50:52) \\n[GCC 8.3.0]', - res(3, 7, 5, '', ' (default, Nov 7 2019, 10:50:52) \\n[GCC 8.3.0]'), - ], - ['python2', res(2, -1, -1, 'python', '')], - // without the "before" the following won't match. - ['python2.a', res(2, -1, -1, 'python', '.a')], - ['python2.b7', res(2, -1, -1, 'python', '.b7')], - ] as [string, ParseResult][]).forEach((data) => { + // plain + ...VERSIONS.map(([v, s]) => [s, { version: v, before: '', after: '' }]), + ['02.7', res(2, 7, -1, '', '')], + ['2.07', res(2, 7, -1, '', '')], + ['2.7.01', res(2, 7, 1, '', '')], + // with before/after + [' 2.7.9 ', res(2, 7, 9, ' ', ' ')], + ['2.7.9-3.2.7', res(2, 7, 9, '', '-3.2.7')], + ['python2.7.exe', res(2, 7, -1, 'python', '.exe')], + ['1.2.3.4.5-x2.2', res(1, 2, 3, '', '.4.5-x2.2')], + ['3.8.1a2', res(3, 8, 1, '', 'a2')], + ['3.8.1-alpha2', res(3, 8, 1, '', '-alpha2')], + [ + '3.7.5 (default, Nov 7 2019, 10:50:52) \\n[GCC 8.3.0]', + res(3, 7, 5, '', ' (default, Nov 7 2019, 10:50:52) \\n[GCC 8.3.0]'), + ], + ['python2', res(2, -1, -1, 'python', '')], + // without the "before" the following won't match. + ['python2.a', res(2, -1, -1, 'python', '.a')], + ['python2.b7', res(2, -1, -1, 'python', '.b7')], + ] as [string, ParseResult][] + ).forEach((data) => { const [verStr, result] = data; if (verStr === '') { return; diff --git a/src/test/common/variables/envVarsService.unit.test.ts b/src/test/common/variables/envVarsService.unit.test.ts index 3709d97b9f62..bcf793d1c984 100644 --- a/src/test/common/variables/envVarsService.unit.test.ts +++ b/src/test/common/variables/envVarsService.unit.test.ts @@ -554,10 +554,12 @@ VAR2_B="${VAR1}\\n"def \n\ }); test('Curly braces are required for substitution', () => { - const vars = parseEnvFile('\ + const vars = parseEnvFile( + '\ SPAM=1234 \n\ EGGS=$SPAM \n\ - '); + ', + ); expect(vars).to.not.equal(undefined, 'Variables is undefiend'); expect(Object.keys(vars!)).lengthOf(2, 'Incorrect number of variables'); @@ -649,11 +651,14 @@ FOO=foo\\$bar \n\ }); test('base substitution variables', () => { - const vars = parseEnvFile('\ + const vars = parseEnvFile( + '\ PYTHONPATH=${REPO}/foo:${REPO}/bar \n\ - ', { - REPO: '/home/user/git/foobar', - }); + ', + { + REPO: '/home/user/git/foobar', + }, + ); expect(vars).to.not.equal(undefined, 'Variables is undefiend'); expect(Object.keys(vars!)).lengthOf(1, 'Incorrect number of variables'); diff --git a/src/test/configuration/environmentTypeComparer.unit.test.ts b/src/test/configuration/environmentTypeComparer.unit.test.ts index bce20fcb0fef..02cffe8daaf9 100644 --- a/src/test/configuration/environmentTypeComparer.unit.test.ts +++ b/src/test/configuration/environmentTypeComparer.unit.test.ts @@ -26,10 +26,10 @@ suite('Environment sorting', () => { getActiveWorkspaceUriStub = sinon.stub().returns({ folderUri: { fsPath: workspacePath } }); getInterpreterTypeDisplayNameStub = sinon.stub(); - interpreterHelper = ({ + interpreterHelper = { getActiveWorkspaceUri: getActiveWorkspaceUriStub, getInterpreterTypeDisplayName: getInterpreterTypeDisplayNameStub, - } as unknown) as IInterpreterHelper; + } as unknown as IInterpreterHelper; const getActivePyenvForDirectory = sinon.stub(pyenv, 'getActivePyenvForDirectory'); getActivePyenvForDirectory.resolves(preferredPyenv); }); @@ -207,8 +207,7 @@ suite('Environment sorting', () => { expected: 1, }, { - title: - 'Microsoft Store interpreter should not come first when there are global interpreters with higher version', + title: 'Microsoft Store interpreter should not come first when there are global interpreters with higher version', envA: { envType: EnvironmentType.MicrosoftStore, version: { major: 3, minor: 10, patch: 2, raw: '3.10.2' }, @@ -250,8 +249,7 @@ suite('Environment sorting', () => { expected: 1, }, { - title: - "If 2 global environments have the same Python version and there's a Conda one, the Conda env should not come first", + title: "If 2 global environments have the same Python version and there's a Conda one, the Conda env should not come first", envA: { envType: EnvironmentType.Conda, type: PythonEnvType.Conda, @@ -267,8 +265,7 @@ suite('Environment sorting', () => { expected: 1, }, { - title: - 'If 2 global environments are of the same type and have the same Python version, they should be sorted by name', + title: 'If 2 global environments are of the same type and have the same Python version, they should be sorted by name', envA: { envType: EnvironmentType.Conda, type: PythonEnvType.Conda, diff --git a/src/test/configuration/interpreterSelector/commands/setInterpreter.unit.test.ts b/src/test/configuration/interpreterSelector/commands/setInterpreter.unit.test.ts index 0016ca339bfe..e55e7f08e605 100644 --- a/src/test/configuration/interpreterSelector/commands/setInterpreter.unit.test.ts +++ b/src/test/configuration/interpreterSelector/commands/setInterpreter.unit.test.ts @@ -204,7 +204,7 @@ suite('Set Interpreter Command', () => { workspace .setup((w) => w.getWorkspaceFolder(TypeMoq.It.isAny())) - .returns(() => (({ uri: { fsPath: workspacePath } } as unknown) as WorkspaceFolder)); + .returns(() => ({ uri: { fsPath: workspacePath } } as unknown as WorkspaceFolder)); setInterpreterCommand = new SetInterpreterCommand( appShell.object, @@ -265,7 +265,7 @@ suite('Set Interpreter Command', () => { .callback((options) => { actualParameters = options; }) - .returns(() => Promise.resolve((undefined as unknown) as QuickPickItem)); + .returns(() => Promise.resolve(undefined as unknown as QuickPickItem)); await setInterpreterCommand._pickInterpreter(multiStepInput.object, state); @@ -276,9 +276,9 @@ suite('Set Interpreter Command', () => { delete actualParameters!.customButtonSetups; delete actualParameters!.onChangeItem; if (typeof actualParameters!.activeItem === 'function') { - const activeItem = await actualParameters!.activeItem(({ items: suggestions } as unknown) as QuickPick< - QuickPickType - >); + const activeItem = await actualParameters!.activeItem({ + items: suggestions, + } as unknown as QuickPick); assert.deepStrictEqual(activeItem, recommended); } else { assert.ok(false, 'Not a function'); @@ -317,7 +317,7 @@ suite('Set Interpreter Command', () => { .callback((options) => { actualParameters = options; }) - .returns(() => Promise.resolve((undefined as unknown) as QuickPickItem)); + .returns(() => Promise.resolve(undefined as unknown as QuickPickItem)); await setInterpreterCommand._pickInterpreter(multiStepInput.object, state, undefined, { showCreateEnvironment: true, @@ -330,9 +330,9 @@ suite('Set Interpreter Command', () => { delete actualParameters!.customButtonSetups; delete actualParameters!.onChangeItem; if (typeof actualParameters!.activeItem === 'function') { - const activeItem = await actualParameters!.activeItem(({ items: suggestions } as unknown) as QuickPick< - QuickPickType - >); + const activeItem = await actualParameters!.activeItem({ + items: suggestions, + } as unknown as QuickPick); assert.deepStrictEqual(activeItem, recommended); } else { assert.ok(false, 'Not a function'); @@ -365,7 +365,7 @@ suite('Set Interpreter Command', () => { .callback((options) => { actualParameters = options; }) - .returns(() => Promise.resolve((undefined as unknown) as QuickPickItem)); + .returns(() => Promise.resolve(undefined as unknown as QuickPickItem)); interpreterSelector.reset(); interpreterSelector .setup((i) => i.getSuggestions(TypeMoq.It.isAny(), TypeMoq.It.isAny())) @@ -380,9 +380,9 @@ suite('Set Interpreter Command', () => { delete actualParameters!.customButtonSetups; delete actualParameters!.onChangeItem; if (typeof actualParameters!.activeItem === 'function') { - const activeItem = await actualParameters!.activeItem(({ items: suggestions } as unknown) as QuickPick< - QuickPickType - >); + const activeItem = await actualParameters!.activeItem({ + items: suggestions, + } as unknown as QuickPick); assert.deepStrictEqual(activeItem, noPythonInstalled); } else { assert.ok(false, 'Not a function'); @@ -396,7 +396,7 @@ suite('Set Interpreter Command', () => { const multiStepInput = TypeMoq.Mock.ofType>(); multiStepInput .setup((i) => i.showQuickPick(TypeMoq.It.isAny())) - .returns(() => Promise.resolve((noPythonInstalled as unknown) as QuickPickItem)); + .returns(() => Promise.resolve(noPythonInstalled as unknown as QuickPickItem)); interpreterSelector.reset(); interpreterSelector .setup((i) => i.getSuggestions(TypeMoq.It.isAny(), TypeMoq.It.isAny())) @@ -416,7 +416,7 @@ suite('Set Interpreter Command', () => { const multiStepInput = TypeMoq.Mock.ofType>(); multiStepInput .setup((i) => i.showQuickPick(TypeMoq.It.isAny())) - .returns(() => Promise.resolve((tipToReloadWindow as unknown) as QuickPickItem)); + .returns(() => Promise.resolve(tipToReloadWindow as unknown as QuickPickItem)); interpreterSelector.reset(); interpreterSelector .setup((i) => i.getSuggestions(TypeMoq.It.isAny(), TypeMoq.It.isAny())) @@ -535,7 +535,7 @@ suite('Set Interpreter Command', () => { .callback((options) => { actualParameters = options; }) - .returns(() => Promise.resolve((undefined as unknown) as QuickPickItem)); + .returns(() => Promise.resolve(undefined as unknown as QuickPickItem)); await setInterpreterCommand._pickInterpreter(multiStepInput.object, state); @@ -647,7 +647,7 @@ suite('Set Interpreter Command', () => { .callback((options) => { actualParameters = options; }) - .returns(() => Promise.resolve((undefined as unknown) as QuickPickItem)); + .returns(() => Promise.resolve(undefined as unknown as QuickPickItem)); await setInterpreterCommand._pickInterpreter( multiStepInput.object, @@ -740,7 +740,7 @@ suite('Set Interpreter Command', () => { .callback((options) => { actualParameters = options; }) - .returns(() => Promise.resolve((undefined as unknown) as QuickPickItem)); + .returns(() => Promise.resolve(undefined as unknown as QuickPickItem)); await setInterpreterCommand._pickInterpreter(multiStepInput.object, state); @@ -752,9 +752,9 @@ suite('Set Interpreter Command', () => { delete actualParameters!.customButtonSetups; delete actualParameters!.onChangeItem; if (typeof actualParameters!.activeItem === 'function') { - const activeItem = await actualParameters!.activeItem(({ items: suggestions } as unknown) as QuickPick< - QuickPickType - >); + const activeItem = await actualParameters!.activeItem({ + items: suggestions, + } as unknown as QuickPick); assert.deepStrictEqual(activeItem, recommended); } else { assert.ok(false, 'Not a function'); @@ -773,7 +773,7 @@ suite('Set Interpreter Command', () => { .callback((options) => { actualParameters = options; }) - .returns(() => Promise.resolve((undefined as unknown) as QuickPickItem)); + .returns(() => Promise.resolve(undefined as unknown as QuickPickItem)); await setInterpreterCommand._pickInterpreter(multiStepInput.object, state); @@ -796,7 +796,7 @@ suite('Set Interpreter Command', () => { .callback((options) => { actualParameters = options; }) - .returns(() => Promise.resolve((undefined as unknown) as QuickPickItem)); + .returns(() => Promise.resolve(undefined as unknown as QuickPickItem)); const refreshPromiseDeferred = createDeferred(); // Assume a refresh is currently going on... when(interpreterService.refreshPromise).thenReturn(refreshPromiseDeferred.promise); @@ -822,7 +822,7 @@ suite('Set Interpreter Command', () => { old: item.interpreter, new: refreshedItem.interpreter, }; - await onChangedCallback!(changeEvent, (quickPick as unknown) as QuickPick); // Invoke callback, meaning that the items are supposed to change. + await onChangedCallback!(changeEvent, quickPick as unknown as QuickPick); // Invoke callback, meaning that the items are supposed to change. assert.deepStrictEqual( quickPick, @@ -907,7 +907,7 @@ suite('Set Interpreter Command', () => { interpreterSelector .setup((i) => i.suggestionToQuickPickItem(TypeMoq.It.isValue(newItem.interpreter), undefined, false)) .returns(() => newItem); - await onChangedCallback!(changeEvent2, (quickPick as unknown) as QuickPick); // Invoke callback, meaning that the items are supposed to change. + await onChangedCallback!(changeEvent2, quickPick as unknown as QuickPick); // Invoke callback, meaning that the items are supposed to change. assert.deepStrictEqual( quickPick, @@ -1008,7 +1008,7 @@ suite('Set Interpreter Command', () => { const multiStepInput = TypeMoq.Mock.ofType>(); multiStepInput .setup((i) => i.showQuickPick(expectedParameters)) - .returns(() => Promise.resolve((undefined as unknown) as QuickPickItem)) + .returns(() => Promise.resolve(undefined as unknown as QuickPickItem)) .verifiable(TypeMoq.Times.once()); await setInterpreterCommand._enterOrBrowseInterpreterPath(multiStepInput.object, state); diff --git a/src/test/configuration/interpreterSelector/interpreterSelector.unit.test.ts b/src/test/configuration/interpreterSelector/interpreterSelector.unit.test.ts index 2ec20be66990..9a49526da5c0 100644 --- a/src/test/configuration/interpreterSelector/interpreterSelector.unit.test.ts +++ b/src/test/configuration/interpreterSelector/interpreterSelector.unit.test.ts @@ -39,7 +39,7 @@ class InterpreterQuickPickItem implements IInterpreterQuickPickItem { public detail?: string; - public interpreter = ({} as unknown) as PythonEnvironment; + public interpreter = {} as unknown as PythonEnvironment; constructor(l: string, p: string, d?: string) { this.path = p; diff --git a/src/test/debugger/envVars.test.ts b/src/test/debugger/envVars.test.ts index ae21c7fd5d49..a2d4a0c215f1 100644 --- a/src/test/debugger/envVars.test.ts +++ b/src/test/debugger/envVars.test.ts @@ -56,13 +56,13 @@ suite('Resolving Environment Variables when Debugging', () => { } async function testBasicProperties(console: ConsoleType, expectedNumberOfVariables: number) { - const args = ({ + const args = { program: '', pythonPath: '', args: [], envFile: '', console, - } as any) as LaunchRequestArguments; + } as any as LaunchRequestArguments; const envVars = await debugEnvParser.getEnvironmentVariables(args); expect(envVars).not.be.undefined; @@ -79,14 +79,14 @@ suite('Resolving Environment Variables when Debugging', () => { test('Confirm base environment variables are merged without overwriting when provided', async () => { const env: Record = { DO_NOT_OVERWRITE: '1' }; - const args = ({ + const args = { program: '', pythonPath: '', args: [], envFile: '', console, env, - } as any) as LaunchRequestArguments; + } as any as LaunchRequestArguments; const baseEnvVars = { CONDA_PREFIX: 'path/to/conda/env', DO_NOT_OVERWRITE: '0' }; const envVars = await debugEnvParser.getEnvironmentVariables(args, baseEnvVars); @@ -118,14 +118,14 @@ suite('Resolving Environment Variables when Debugging', () => { env[prop2] = prop2; mockProcess.env[prop3] = prop3; - const args = ({ + const args = { program: '', pythonPath: '', args: [], envFile: '', console, env, - } as any) as LaunchRequestArguments; + } as any as LaunchRequestArguments; const envVars = await debugEnvParser.getEnvironmentVariables(args); @@ -183,14 +183,14 @@ suite('Resolving Environment Variables when Debugging', () => { env[prop2] = prop2; mockProcess.env[prop3] = prop3; - const args = ({ + const args = { program: '', pythonPath: '', args: [], envFile: '', console, env, - } as any) as LaunchRequestArguments; + } as any as LaunchRequestArguments; const envVars = await debugEnvParser.getEnvironmentVariables(args); expect(envVars).not.be.undefined; diff --git a/src/test/debugger/extension/adapter/factory.unit.test.ts b/src/test/debugger/extension/adapter/factory.unit.test.ts index 50984327e40d..06c8433e2c92 100644 --- a/src/test/debugger/extension/adapter/factory.unit.test.ts +++ b/src/test/debugger/extension/adapter/factory.unit.test.ts @@ -86,9 +86,9 @@ suite('Debugging - Adapter Factory', () => { ).thenReturn(instance(state)); const configurationService = mock(ConfigurationService); - when(configurationService.getSettings(undefined)).thenReturn(({ + when(configurationService.getSettings(undefined)).thenReturn({ experiments: { enabled: true }, - } as any) as IPythonSettings); + } as any as IPythonSettings); interpreterService = mock(InterpreterService); diff --git a/src/test/debugger/extension/adapter/outdatedDebuggerPrompt.unit.test.ts b/src/test/debugger/extension/adapter/outdatedDebuggerPrompt.unit.test.ts index 9f9497317417..357e3b0424f6 100644 --- a/src/test/debugger/extension/adapter/outdatedDebuggerPrompt.unit.test.ts +++ b/src/test/debugger/extension/adapter/outdatedDebuggerPrompt.unit.test.ts @@ -38,9 +38,9 @@ suite('Debugging - Outdated Debugger Prompt tests.', () => { setup(() => { const configurationService = mock(ConfigurationService); - when(configurationService.getSettings(undefined)).thenReturn(({ + when(configurationService.getSettings(undefined)).thenReturn({ experiments: { enabled: true }, - } as any) as IPythonSettings); + } as any as IPythonSettings); showInformationMessageStub = sinon.stub(windowApis, 'showInformationMessage'); browserLaunchStub = sinon.stub(browserApis, 'launch'); diff --git a/src/test/debugger/extension/attachQuickPick/provider.unit.test.ts b/src/test/debugger/extension/attachQuickPick/provider.unit.test.ts index 64d9103f3c5d..fdeda6af60f1 100644 --- a/src/test/debugger/extension/attachQuickPick/provider.unit.test.ts +++ b/src/test/debugger/extension/attachQuickPick/provider.unit.test.ts @@ -397,8 +397,7 @@ ProcessId=8026\r { label: 'python.exe', description: '8026', - detail: - 'C:\\Users\\Contoso\\AppData\\Local\\Programs\\Python\\Python37\\python.exe c:/Users/Contoso/Documents/foo_bar.py', + detail: 'C:\\Users\\Contoso\\AppData\\Local\\Programs\\Python\\Python37\\python.exe c:/Users/Contoso/Documents/foo_bar.py', id: '8026', processName: 'python.exe', commandLine: @@ -407,8 +406,7 @@ ProcessId=8026\r { label: 'python.exe', description: '6028', - detail: - 'C:\\Users\\Contoso\\AppData\\Local\\Programs\\Python\\Python37\\python.exe c:/Users/Contoso/Documents/hello_world.py', + detail: 'C:\\Users\\Contoso\\AppData\\Local\\Programs\\Python\\Python37\\python.exe c:/Users/Contoso/Documents/hello_world.py', id: '6028', processName: 'python.exe', commandLine: diff --git a/src/test/debugger/extension/attachQuickPick/wmicProcessParser.unit.test.ts b/src/test/debugger/extension/attachQuickPick/wmicProcessParser.unit.test.ts index e29490c47926..ba36cfdf61ec 100644 --- a/src/test/debugger/extension/attachQuickPick/wmicProcessParser.unit.test.ts +++ b/src/test/debugger/extension/attachQuickPick/wmicProcessParser.unit.test.ts @@ -70,8 +70,7 @@ ProcessId=6028\r\n\ { label: 'python.exe', description: '6028', - detail: - 'C:\\Users\\Contoso\\AppData\\Local\\Programs\\Python\\Python37\\python.exe c:/Users/Contoso/Documents/hello_world.py', + detail: 'C:\\Users\\Contoso\\AppData\\Local\\Programs\\Python\\Python37\\python.exe c:/Users/Contoso/Documents/hello_world.py', id: '6028', processName: 'python.exe', commandLine: @@ -148,8 +147,7 @@ ProcessId=6028\r\n\ { label: 'python.exe', description: '6028', - detail: - 'C:\\Users\\Contoso\\AppData\\Local\\Programs\\Python\\Python37\\python.exe c:/Users/Contoso/Documents/hello_world.py', + detail: 'C:\\Users\\Contoso\\AppData\\Local\\Programs\\Python\\Python37\\python.exe c:/Users/Contoso/Documents/hello_world.py', id: '6028', processName: 'python.exe', commandLine: @@ -199,8 +197,7 @@ ProcessId=6028\r\n\ { label: 'python.exe', description: '6028', - detail: - 'C:\\Users\\Contoso\\AppData\\Local\\Programs\\Python\\Python37\\python.exe c:/Users/Contoso/Documents/hello_world.py', + detail: 'C:\\Users\\Contoso\\AppData\\Local\\Programs\\Python\\Python37\\python.exe c:/Users/Contoso/Documents/hello_world.py', id: '6028', processName: 'python.exe', commandLine: diff --git a/src/test/debugger/extension/configuration/debugConfigurationService.unit.test.ts b/src/test/debugger/extension/configuration/debugConfigurationService.unit.test.ts index ae13ad375371..5477f7e6ead2 100644 --- a/src/test/debugger/extension/configuration/debugConfigurationService.unit.test.ts +++ b/src/test/debugger/extension/configuration/debugConfigurationService.unit.test.ts @@ -22,9 +22,9 @@ suite('Debugging - Configuration Service', () => { configService = new TestPythonDebugConfigurationService(attachResolver.object, launchResolver.object); }); test('Should use attach resolver when passing attach config', async () => { - const config = ({ + const config = { request: 'attach', - } as DebugConfiguration) as AttachRequestArguments; + } as DebugConfiguration as AttachRequestArguments; const folder = { name: '1', index: 0, uri: Uri.parse('1234') }; const expectedConfig = { yay: 1 }; @@ -32,7 +32,7 @@ suite('Debugging - Configuration Service', () => { .setup((a) => a.resolveDebugConfiguration(typemoq.It.isValue(folder), typemoq.It.isValue(config), typemoq.It.isAny()), ) - .returns(() => Promise.resolve((expectedConfig as unknown) as AttachRequestArguments)) + .returns(() => Promise.resolve(expectedConfig as unknown as AttachRequestArguments)) .verifiable(typemoq.Times.once()); launchResolver .setup((a) => a.resolveDebugConfiguration(typemoq.It.isAny(), typemoq.It.isAny(), typemoq.It.isAny())) @@ -53,11 +53,11 @@ suite('Debugging - Configuration Service', () => { .setup((a) => a.resolveDebugConfiguration( typemoq.It.isValue(folder), - typemoq.It.isValue((config as DebugConfiguration) as LaunchRequestArguments), + typemoq.It.isValue(config as DebugConfiguration as LaunchRequestArguments), typemoq.It.isAny(), ), ) - .returns(() => Promise.resolve((expectedConfig as unknown) as LaunchRequestArguments)) + .returns(() => Promise.resolve(expectedConfig as unknown as LaunchRequestArguments)) .verifiable(typemoq.Times.once()); attachResolver .setup((a) => a.resolveDebugConfiguration(typemoq.It.isAny(), typemoq.It.isAny(), typemoq.It.isAny())) diff --git a/src/test/debugger/extension/configuration/resolvers/base.unit.test.ts b/src/test/debugger/extension/configuration/resolvers/base.unit.test.ts index 4da645bc34ac..df700fb28cc7 100644 --- a/src/test/debugger/extension/configuration/resolvers/base.unit.test.ts +++ b/src/test/debugger/extension/configuration/resolvers/base.unit.test.ts @@ -156,7 +156,7 @@ suite('Debugging - Config Resolver', () => { expect(uri).to.be.deep.equal(undefined, 'not undefined'); }); test('Do nothing if debug configuration is undefined', async () => { - await resolver.resolveAndUpdatePythonPath(undefined, (undefined as unknown) as LaunchRequestArguments); + await resolver.resolveAndUpdatePythonPath(undefined, undefined as unknown as LaunchRequestArguments); }); test('python in debug config must point to pythonPath in settings if pythonPath in config is not set', async () => { const config = {}; diff --git a/src/test/debugger/extension/configuration/resolvers/launch.unit.test.ts b/src/test/debugger/extension/configuration/resolvers/launch.unit.test.ts index f312c99b1cbc..239ca4ab799f 100644 --- a/src/test/debugger/extension/configuration/resolvers/launch.unit.test.ts +++ b/src/test/debugger/extension/configuration/resolvers/launch.unit.test.ts @@ -149,8 +149,9 @@ getInfoPerOS().forEach(([osName, osType, path]) => { return config; } - const interpreterPath = configService.object.getSettings(workspaceFolder ? workspaceFolder.uri : undefined) - .pythonPath; + const interpreterPath = configService.object.getSettings( + workspaceFolder ? workspaceFolder.uri : undefined, + ).pythonPath; for (const key of Object.keys(config)) { const value = config[key]; if (typeof value === 'string') { diff --git a/src/test/debugger/extension/debugCommands.unit.test.ts b/src/test/debugger/extension/debugCommands.unit.test.ts index 7d2463072f06..04a9c3f6e44f 100644 --- a/src/test/debugger/extension/debugCommands.unit.test.ts +++ b/src/test/debugger/extension/debugCommands.unit.test.ts @@ -34,7 +34,7 @@ suite('Debugging - commands', () => { interpreterService = typemoq.Mock.ofType(); interpreterService .setup((i) => i.getActiveInterpreter(typemoq.It.isAny())) - .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: 'ps' } as unknown as PythonEnvironment)); sinon.stub(telemetry, 'sendTelemetryEvent').callsFake(() => { /** noop */ }); diff --git a/src/test/debugger/utils.ts b/src/test/debugger/utils.ts index 9ccb8958b660..ff7a394cfb7a 100644 --- a/src/test/debugger/utils.ts +++ b/src/test/debugger/utils.ts @@ -80,9 +80,9 @@ class DebugAdapterTracker { this.tracked.dapHandler(src, msg); } if (msg.type === 'event') { - const event = ((msg as unknown) as DebugProtocol.Event).event; + const event = (msg as unknown as DebugProtocol.Event).event; if (event === 'output') { - this.onOutputEvent((msg as unknown) as DebugProtocol.OutputEvent); + this.onOutputEvent(msg as unknown as DebugProtocol.OutputEvent); } } } @@ -233,12 +233,12 @@ class DebuggerSession { public handleDAPMessage(_src: DAPSource, baseMsg: DebugProtocol.ProtocolMessage) { if (baseMsg.type === 'event') { - const event = ((baseMsg as unknown) as DebugProtocol.Event).event; + const event = (baseMsg as unknown as DebugProtocol.Event).event; if (event === 'stopped') { - const msg = (baseMsg as unknown) as DebugProtocol.StoppedEvent; + const msg = baseMsg as unknown as DebugProtocol.StoppedEvent; this.stopped = { breakpoint: msg.body.reason === 'breakpoint', - threadId: (msg.body.threadId as unknown) as number, + threadId: msg.body.threadId as unknown as number, }; } else { // For now there aren't any other events we care about. diff --git a/src/test/environmentApi.unit.test.ts b/src/test/environmentApi.unit.test.ts index 2e5d13161f7b..68c7d205718f 100644 --- a/src/test/environmentApi.unit.test.ts +++ b/src/test/environmentApi.unit.test.ts @@ -138,7 +138,7 @@ suite('Python Environment API', () => { test('getEnvironmentVariables: With WorkspaceFolder resource', async () => { const resource = Uri.file('x'); - const folder = ({ uri: resource } as unknown) as WorkspaceFolder; + const folder = { uri: resource } as unknown as WorkspaceFolder; const envVars = { PATH: 'path' }; envVarsProvider.setup((e) => e.getEnvironmentVariablesSync(resource)).returns(() => envVars); const vars = environmentApi.getEnvironmentVariables(folder); @@ -161,7 +161,7 @@ suite('Python Environment API', () => { const pythonPath = 'this/is/a/test/path'; configService .setup((c) => c.getSettings(undefined)) - .returns(() => (({ pythonPath } as unknown) as IPythonSettings)); + .returns(() => ({ pythonPath } as unknown as IPythonSettings)); const actual = environmentApi.getActiveEnvironmentPath(); assert.deepEqual(actual, { id: normCasePath(pythonPath), @@ -173,7 +173,7 @@ suite('Python Environment API', () => { const pythonPath = 'python'; configService .setup((c) => c.getSettings(undefined)) - .returns(() => (({ pythonPath } as unknown) as IPythonSettings)); + .returns(() => ({ pythonPath } as unknown as IPythonSettings)); const actual = environmentApi.getActiveEnvironmentPath(); assert.deepEqual(actual, { id: 'DEFAULT_PYTHON', @@ -186,7 +186,7 @@ suite('Python Environment API', () => { const resource = Uri.file(__filename); configService .setup((c) => c.getSettings(resource)) - .returns(() => (({ pythonPath } as unknown) as IPythonSettings)); + .returns(() => ({ pythonPath } as unknown as IPythonSettings)); const actual = environmentApi.getActiveEnvironmentPath(resource); assert.deepEqual(actual, { id: normCasePath(pythonPath), diff --git a/src/test/extensionSettings.ts b/src/test/extensionSettings.ts index 66a77589a770..e5f581416dd2 100644 --- a/src/test/extensionSettings.ts +++ b/src/test/extensionSettings.ts @@ -36,7 +36,8 @@ export function getExtensionSettings(resource: Uri | undefined): IPythonSettings return undefined; } } - const pythonSettings = require('../client/common/configSettings') as typeof import('../client/common/configSettings'); + const pythonSettings = + require('../client/common/configSettings') as typeof import('../client/common/configSettings'); const workspaceService = new WorkspaceService(); const workspaceMemento = new MockMemento(); const globalMemento = new MockMemento(); diff --git a/src/test/initialize.ts b/src/test/initialize.ts index 0ed75a0aa5c1..aa5149fad53e 100644 --- a/src/test/initialize.ts +++ b/src/test/initialize.ts @@ -43,7 +43,7 @@ export async function initialize(): Promise { configSettings.PythonSettings.dispose(); } - return (api as any) as IExtensionTestApi; + return api as any as IExtensionTestApi; } export async function activateExtension() { const extension = vscode.extensions.getExtension(PVSC_EXTENSION_ID_FOR_TESTS)!; diff --git a/src/test/install/channelManager.channels.test.ts b/src/test/install/channelManager.channels.test.ts index e43fa21daf17..3ac277e04ff6 100644 --- a/src/test/install/channelManager.channels.test.ts +++ b/src/test/install/channelManager.channels.test.ts @@ -82,9 +82,7 @@ suite('Installation - installation channels', () => { .callback((i: string[]) => { items = i; }) - .returns( - () => new Promise((resolve, _reject) => resolve(undefined)), - ); + .returns(() => new Promise((resolve, _reject) => resolve(undefined))); installer1.setup((x) => x.displayName).returns(() => 'Name 1'); installer2.setup((x) => x.displayName).returns(() => 'Name 2'); @@ -102,9 +100,7 @@ suite('Installation - installation channels', () => { const installer = createTypeMoq(); installer .setup((x) => x.isSupported(TypeMoq.It.isAny())) - .returns( - () => new Promise((resolve) => resolve(supported)), - ); + .returns(() => new Promise((resolve) => resolve(supported))); installer.setup((x) => x.priority).returns(() => priority || 0); serviceManager.addSingletonInstance(IModuleInstaller, installer.object, name); return installer; diff --git a/src/test/install/channelManager.messages.test.ts b/src/test/install/channelManager.messages.test.ts index 1e9953b8b753..31d0f64a0aa1 100644 --- a/src/test/install/channelManager.messages.test.ts +++ b/src/test/install/channelManager.messages.test.ts @@ -161,9 +161,7 @@ suite('Installation - channel messages', () => { }; interpreters .setup((x) => x.getActiveInterpreter(TypeMoq.It.isAny())) - .returns( - () => new Promise((resolve, _reject) => resolve(activeInterpreter)), - ); + .returns(() => new Promise((resolve, _reject) => resolve(activeInterpreter))); const channels = new InstallationChannelManager(serviceContainer); let url = ''; @@ -175,9 +173,7 @@ suite('Installation - channel messages', () => { message = m; search = s; }) - .returns( - () => new Promise((resolve, _reject) => resolve(search)), - ); + .returns(() => new Promise((resolve, _reject) => resolve(search))); appShell .setup((x) => x.openUrl(TypeMoq.It.isAnyString())) .callback((s: string) => { diff --git a/src/test/interpreters/activation/indicatorPrompt.unit.test.ts b/src/test/interpreters/activation/indicatorPrompt.unit.test.ts index b15cd84dc01a..10d07a808288 100644 --- a/src/test/interpreters/activation/indicatorPrompt.unit.test.ts +++ b/src/test/interpreters/activation/indicatorPrompt.unit.test.ts @@ -49,20 +49,20 @@ suite('Terminal Activation Indicator Prompt', () => { shell = mock(); terminalManager = mock(); interpreterService = mock(); - when(interpreterService.getActiveInterpreter(anything())).thenResolve(({ + when(interpreterService.getActiveInterpreter(anything())).thenResolve({ envName, type, - } as unknown) as PythonEnvironment); + } as unknown as PythonEnvironment); experimentService = mock(); activeResourceService = mock(); persistentStateFactory = mock(); terminalEnvVarCollectionService = mock(); configurationService = mock(); - when(configurationService.getSettings(anything())).thenReturn(({ + when(configurationService.getSettings(anything())).thenReturn({ terminal: { activateEnvironment: true, }, - } as unknown) as IPythonSettings); + } as unknown as IPythonSettings); notificationEnabled = mock>(); terminalEventEmitter = new EventEmitter(); when(persistentStateFactory.createGlobalPersistentState(anything(), true)).thenReturn( @@ -89,11 +89,11 @@ suite('Terminal Activation Indicator Prompt', () => { test('Show notification when a new terminal is opened for which there is no prompt set', async () => { const resource = Uri.file('a'); - const terminal = ({ + const terminal = { creationOptions: { cwd: resource, }, - } as unknown) as Terminal; + } as unknown as Terminal; when(terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)).thenReturn(false); when(notificationEnabled.value).thenReturn(true); when(shell.showInformationMessage(expectedMessage, ...prompts)).thenResolve(undefined); @@ -107,17 +107,17 @@ suite('Terminal Activation Indicator Prompt', () => { test('Do not show notification if automatic terminal activation is turned off', async () => { reset(configurationService); - when(configurationService.getSettings(anything())).thenReturn(({ + when(configurationService.getSettings(anything())).thenReturn({ terminal: { activateEnvironment: false, }, - } as unknown) as IPythonSettings); + } as unknown as IPythonSettings); const resource = Uri.file('a'); - const terminal = ({ + const terminal = { creationOptions: { cwd: resource, }, - } as unknown) as Terminal; + } as unknown as Terminal; when(terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)).thenReturn(false); when(notificationEnabled.value).thenReturn(true); when(shell.showInformationMessage(expectedMessage, ...prompts)).thenResolve(undefined); @@ -131,11 +131,11 @@ suite('Terminal Activation Indicator Prompt', () => { test('When not in experiment, do not show notification for the same', async () => { const resource = Uri.file('a'); - const terminal = ({ + const terminal = { creationOptions: { cwd: resource, }, - } as unknown) as Terminal; + } as unknown as Terminal; when(terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)).thenReturn(false); when(notificationEnabled.value).thenReturn(true); when(shell.showInformationMessage(expectedMessage, ...prompts)).thenResolve(undefined); @@ -151,11 +151,11 @@ suite('Terminal Activation Indicator Prompt', () => { test('Do not show notification if notification is disabled', async () => { const resource = Uri.file('a'); - const terminal = ({ + const terminal = { creationOptions: { cwd: resource, }, - } as unknown) as Terminal; + } as unknown as Terminal; when(terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)).thenReturn(false); when(notificationEnabled.value).thenReturn(false); when(shell.showInformationMessage(expectedMessage, ...prompts)).thenResolve(undefined); @@ -169,11 +169,11 @@ suite('Terminal Activation Indicator Prompt', () => { test('Do not show notification when a new terminal is opened for which there is prompt set', async () => { const resource = Uri.file('a'); - const terminal = ({ + const terminal = { creationOptions: { cwd: resource, }, - } as unknown) as Terminal; + } as unknown as Terminal; when(terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)).thenReturn(true); when(notificationEnabled.value).thenReturn(true); when(shell.showInformationMessage(expectedMessage, ...prompts)).thenResolve(undefined); @@ -187,11 +187,11 @@ suite('Terminal Activation Indicator Prompt', () => { test("Disable notification if `Don't show again` is clicked", async () => { const resource = Uri.file('a'); - const terminal = ({ + const terminal = { creationOptions: { cwd: resource, }, - } as unknown) as Terminal; + } as unknown as Terminal; when(terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)).thenReturn(false); when(notificationEnabled.value).thenReturn(true); when(notificationEnabled.updateValue(false)).thenResolve(); @@ -208,11 +208,11 @@ suite('Terminal Activation Indicator Prompt', () => { test('Do not disable notification if prompt is closed', async () => { const resource = Uri.file('a'); - const terminal = ({ + const terminal = { creationOptions: { cwd: resource, }, - } as unknown) as Terminal; + } as unknown as Terminal; when(terminalEnvVarCollectionService.isTerminalPromptSetCorrectly(resource)).thenReturn(false); when(notificationEnabled.value).thenReturn(true); when(notificationEnabled.updateValue(false)).thenResolve(); diff --git a/src/test/interpreters/activation/terminalEnvVarCollectionService.unit.test.ts b/src/test/interpreters/activation/terminalEnvVarCollectionService.unit.test.ts index 7016a25c7a4e..cd148757ca0b 100644 --- a/src/test/interpreters/activation/terminalEnvVarCollectionService.unit.test.ts +++ b/src/test/interpreters/activation/terminalEnvVarCollectionService.unit.test.ts @@ -101,10 +101,10 @@ suite('Terminal Environment Variable Collection Service', () => { process.env, ); configService = mock(); - when(configService.getSettings(anything())).thenReturn(({ + when(configService.getSettings(anything())).thenReturn({ terminal: { activateEnvironment: true }, pythonPath: displayPath, - } as unknown) as IPythonSettings); + } as unknown as IPythonSettings); when(collection.clear()).thenResolve(); terminalEnvVarCollectionService = new TerminalEnvVarCollectionService( instance(platform), @@ -217,9 +217,9 @@ suite('Terminal Environment Variable Collection Service', () => { environmentActivationService.getActivatedEnvironmentVariables(anything(), undefined, undefined, 'bash'), ).thenResolve(envVars); - when(interpreterService.getActiveInterpreter(anything())).thenResolve(({ + when(interpreterService.getActiveInterpreter(anything())).thenResolve({ envName: 'envName', - } as unknown) as PythonEnvironment); + } as unknown as PythonEnvironment); when(collection.replace(anything(), anything(), anything())).thenResolve(); when(collection.delete(anything())).thenResolve(); @@ -245,11 +245,11 @@ suite('Terminal Environment Variable Collection Service', () => { when( environmentActivationService.getActivatedEnvironmentVariables(anything(), undefined, undefined, 'bash'), ).thenResolve(envVars); - when(interpreterService.getActiveInterpreter(anything())).thenResolve(({ + when(interpreterService.getActiveInterpreter(anything())).thenResolve({ type: PythonEnvType.Virtual, envName: 'envName', envPath: 'prefix/to/conda', - } as unknown) as PythonEnvironment); + } as unknown as PythonEnvironment); when(collection.replace(anything(), anything(), anything())).thenResolve(); when(collection.delete(anything())).thenResolve(); @@ -269,11 +269,11 @@ suite('Terminal Environment Variable Collection Service', () => { when( environmentActivationService.getActivatedEnvironmentVariables(anything(), undefined, undefined, 'bash'), ).thenResolve(envVars); - when(interpreterService.getActiveInterpreter(anything())).thenResolve(({ + when(interpreterService.getActiveInterpreter(anything())).thenResolve({ type: PythonEnvType.Virtual, envName: 'envName', envPath: 'prefix/to/conda', - } as unknown) as PythonEnvironment); + } as unknown as PythonEnvironment); when(collection.replace(anything(), anything(), anything())).thenResolve(); when(collection.delete(anything())).thenResolve(); @@ -294,11 +294,11 @@ suite('Terminal Environment Variable Collection Service', () => { when( environmentActivationService.getActivatedEnvironmentVariables(anything(), undefined, undefined, 'bash'), ).thenResolve(envVars); - when(interpreterService.getActiveInterpreter(anything())).thenResolve(({ + when(interpreterService.getActiveInterpreter(anything())).thenResolve({ type: PythonEnvType.Conda, envName: 'envName', envPath: 'prefix/to/conda', - } as unknown) as PythonEnvironment); + } as unknown as PythonEnvironment); when(collection.replace(anything(), anything(), anything())).thenResolve(); when(collection.delete(anything())).thenResolve(); @@ -465,10 +465,10 @@ suite('Terminal Environment Variable Collection Service', () => { when(collection.replace(anything(), anything(), anything())).thenResolve(); when(collection.delete(anything())).thenResolve(); reset(configService); - when(configService.getSettings(anything())).thenReturn(({ + when(configService.getSettings(anything())).thenReturn({ terminal: { activateEnvironment: false }, pythonPath: displayPath, - } as unknown) as IPythonSettings); + } as unknown as IPythonSettings); await terminalEnvVarCollectionService._applyCollection(undefined, customShell); @@ -512,9 +512,9 @@ suite('Terminal Environment Variable Collection Service', () => { name: 'workspace1', index: 0, }; - when(interpreterService.getActiveInterpreter(resource)).thenResolve(({ + when(interpreterService.getActiveInterpreter(resource)).thenResolve({ type: PythonEnvType.Virtual, - } as unknown) as PythonEnvironment); + } as unknown as PythonEnvironment); when(workspaceService.getWorkspaceFolder(resource)).thenReturn(workspaceFolder); when( environmentActivationService.getActivatedEnvironmentVariables(resource, undefined, undefined, ps1Shell), @@ -540,9 +540,9 @@ suite('Terminal Environment Variable Collection Service', () => { name: 'workspace1', index: 0, }; - when(interpreterService.getActiveInterpreter(resource)).thenResolve(({ + when(interpreterService.getActiveInterpreter(resource)).thenResolve({ type: PythonEnvType.Virtual, - } as unknown) as PythonEnvironment); + } as unknown as PythonEnvironment); when(workspaceService.getWorkspaceFolder(resource)).thenReturn(workspaceFolder); when( environmentActivationService.getActivatedEnvironmentVariables(resource, undefined, undefined, ps1Shell), @@ -566,11 +566,11 @@ suite('Terminal Environment Variable Collection Service', () => { name: 'workspace1', index: 0, }; - when(interpreterService.getActiveInterpreter(resource)).thenResolve(({ + when(interpreterService.getActiveInterpreter(resource)).thenResolve({ type: PythonEnvType.Conda, envName: 'envName', envPath: 'prefix/to/conda', - } as unknown) as PythonEnvironment); + } as unknown as PythonEnvironment); when(workspaceService.getWorkspaceFolder(resource)).thenReturn(workspaceFolder); when( environmentActivationService.getActivatedEnvironmentVariables(resource, undefined, undefined, ps1Shell), @@ -598,11 +598,11 @@ suite('Terminal Environment Variable Collection Service', () => { name: 'workspace1', index: 0, }; - when(interpreterService.getActiveInterpreter(resource)).thenResolve(({ + when(interpreterService.getActiveInterpreter(resource)).thenResolve({ type: PythonEnvType.Conda, envName: 'base', envPath: 'prefix/to/conda', - } as unknown) as PythonEnvironment); + } as unknown as PythonEnvironment); when(workspaceService.getWorkspaceFolder(resource)).thenReturn(workspaceFolder); when( environmentActivationService.getActivatedEnvironmentVariables(resource, undefined, undefined, ps1Shell), @@ -626,11 +626,11 @@ suite('Terminal Environment Variable Collection Service', () => { name: 'workspace1', index: 0, }; - when(interpreterService.getActiveInterpreter(resource)).thenResolve(({ + when(interpreterService.getActiveInterpreter(resource)).thenResolve({ type: PythonEnvType.Conda, envName: 'envName', envPath: 'prefix/to/conda', - } as unknown) as PythonEnvironment); + } as unknown as PythonEnvironment); when(workspaceService.getWorkspaceFolder(resource)).thenReturn(workspaceFolder); when( environmentActivationService.getActivatedEnvironmentVariables(resource, undefined, undefined, ps1Shell), @@ -653,9 +653,9 @@ suite('Terminal Environment Variable Collection Service', () => { name: 'workspace1', index: 0, }; - when(interpreterService.getActiveInterpreter(resource)).thenResolve(({ + when(interpreterService.getActiveInterpreter(resource)).thenResolve({ type: undefined, - } as unknown) as PythonEnvironment); + } as unknown as PythonEnvironment); when(workspaceService.getWorkspaceFolder(resource)).thenReturn(workspaceFolder); when( environmentActivationService.getActivatedEnvironmentVariables(resource, undefined, undefined, ps1Shell), @@ -679,9 +679,9 @@ suite('Terminal Environment Variable Collection Service', () => { name: 'workspace1', index: 0, }; - when(interpreterService.getActiveInterpreter(resource)).thenResolve(({ + when(interpreterService.getActiveInterpreter(resource)).thenResolve({ type: PythonEnvType.Virtual, - } as unknown) as PythonEnvironment); + } as unknown as PythonEnvironment); when(workspaceService.getWorkspaceFolder(resource)).thenReturn(workspaceFolder); when( environmentActivationService.getActivatedEnvironmentVariables(resource, undefined, undefined, windowsShell), @@ -705,9 +705,9 @@ suite('Terminal Environment Variable Collection Service', () => { name: 'workspace1', index: 0, }; - when(interpreterService.getActiveInterpreter(resource)).thenResolve(({ + when(interpreterService.getActiveInterpreter(resource)).thenResolve({ type: PythonEnvType.Virtual, - } as unknown) as PythonEnvironment); + } as unknown as PythonEnvironment); when(workspaceService.getWorkspaceFolder(resource)).thenReturn(workspaceFolder); when( environmentActivationService.getActivatedEnvironmentVariables(resource, undefined, undefined, windowsShell), diff --git a/src/test/interpreters/display.unit.test.ts b/src/test/interpreters/display.unit.test.ts index 7d53fbfc0561..fb00f2e7f38f 100644 --- a/src/test/interpreters/display.unit.test.ts +++ b/src/test/interpreters/display.unit.test.ts @@ -236,10 +236,10 @@ suite('Interpreters Display', () => { const expectedDisplayName = '3.10.1'; setupWorkspaceFolder(resource, workspaceFolder); - const pythonInterpreter: PythonEnvironment = ({ + const pythonInterpreter: PythonEnvironment = { detailedDisplayName: displayName, path: pythonPath, - } as any) as PythonEnvironment; + } as any as PythonEnvironment; interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isValue(workspaceFolder))) .returns(() => Promise.resolve(pythonInterpreter)); diff --git a/src/test/interpreters/virtualEnvs/activatedEnvLaunch.unit.test.ts b/src/test/interpreters/virtualEnvs/activatedEnvLaunch.unit.test.ts index 2ebdecd000d1..aa0607c50b93 100644 --- a/src/test/interpreters/virtualEnvs/activatedEnvLaunch.unit.test.ts +++ b/src/test/interpreters/virtualEnvs/activatedEnvLaunch.unit.test.ts @@ -74,7 +74,7 @@ suite('Activated Env Launch', async () => { process.env.CONDA_SHLVL = '1'; interpreterService .setup((i) => i.getInterpreterDetails(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ envName: 'env' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ envName: 'env' } as unknown as PythonEnvironment)); workspaceService.setup((w) => w.workspaceFile).returns(() => undefined); const workspaceFolder: WorkspaceFolder = { name: 'one', uri, index: 0 }; workspaceService.setup((w) => w.workspaceFolders).returns(() => [workspaceFolder]); @@ -107,7 +107,7 @@ suite('Activated Env Launch', async () => { process.env.CONDA_SHLVL = '1'; interpreterService .setup((i) => i.getInterpreterDetails(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ envName: 'env' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ envName: 'env' } as unknown as PythonEnvironment)); workspaceService.setup((w) => w.workspaceFile).returns(() => undefined); const workspaceFolder: WorkspaceFolder = { name: 'one', uri, index: 0 }; workspaceService.setup((w) => w.workspaceFolders).returns(() => [workspaceFolder]); @@ -140,7 +140,7 @@ suite('Activated Env Launch', async () => { process.env.CONDA_AUTO_ACTIVATE_BASE = 'false'; interpreterService .setup((i) => i.getInterpreterDetails(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ envName: 'base' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ envName: 'base' } as unknown as PythonEnvironment)); workspaceService.setup((w) => w.workspaceFile).returns(() => undefined); const workspaceFolder: WorkspaceFolder = { name: 'one', uri, index: 0 }; workspaceService.setup((w) => w.workspaceFolders).returns(() => [workspaceFolder]); @@ -173,7 +173,7 @@ suite('Activated Env Launch', async () => { process.env.CONDA_AUTO_ACTIVATE_BASE = 'true'; interpreterService .setup((i) => i.getInterpreterDetails(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ envName: 'base' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ envName: 'base' } as unknown as PythonEnvironment)); workspaceService.setup((w) => w.workspaceFile).returns(() => undefined); const workspaceFolder: WorkspaceFolder = { name: 'one', uri, index: 0 }; workspaceService.setup((w) => w.workspaceFolders).returns(() => [workspaceFolder]); @@ -205,7 +205,7 @@ suite('Activated Env Launch', async () => { process.env.VIRTUAL_ENV = virtualEnvPrefix; interpreterService .setup((i) => i.getInterpreterDetails(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ envName: 'base' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ envName: 'base' } as unknown as PythonEnvironment)); workspaceService.setup((w) => w.workspaceFile).returns(() => undefined); const workspaceFolder: WorkspaceFolder = { name: 'one', uri, index: 0 }; workspaceService.setup((w) => w.workspaceFolders).returns(() => [workspaceFolder]); @@ -237,7 +237,7 @@ suite('Activated Env Launch', async () => { process.env.CONDA_SHLVL = '1'; interpreterService .setup((i) => i.getInterpreterDetails(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ envName: 'env' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ envName: 'env' } as unknown as PythonEnvironment)); workspaceService.setup((w) => w.workspaceFile).returns(() => undefined); workspaceService.setup((w) => w.workspaceFolders).returns(() => []); pythonPathUpdaterService @@ -267,7 +267,7 @@ suite('Activated Env Launch', async () => { process.env.VIRTUAL_ENV = virtualEnvPrefix; interpreterService .setup((i) => i.getInterpreterDetails(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ envName: 'base' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ envName: 'base' } as unknown as PythonEnvironment)); workspaceService.setup((w) => w.workspaceFile).returns(() => uri); const workspaceFolder: WorkspaceFolder = { name: 'one', uri, index: 0 }; workspaceService.setup((w) => w.workspaceFolders).returns(() => [workspaceFolder]); @@ -346,7 +346,7 @@ suite('Activated Env Launch', async () => { process.env.CONDA_SHLVL = '1'; interpreterService .setup((i) => i.getInterpreterDetails(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ envName: 'base' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ envName: 'base' } as unknown as PythonEnvironment)); workspaceService.setup((w) => w.workspaceFile).returns(() => undefined); const workspaceFolder: WorkspaceFolder = { name: 'one', uri, index: 0 }; workspaceService.setup((w) => w.workspaceFolders).returns(() => [workspaceFolder]); @@ -368,9 +368,7 @@ suite('Activated Env Launch', async () => { processService .setup((p) => p.shellExec('conda config --get auto_activate_base')) .returns(() => - Promise.resolve(({ stdout: '--set auto_activate_base False' } as unknown) as ExecutionResult< - string - >), + Promise.resolve({ stdout: '--set auto_activate_base False' } as unknown as ExecutionResult), ); activatedEnvLaunch = new ActivatedEnvironmentLaunch( workspaceService.object, @@ -388,7 +386,7 @@ suite('Activated Env Launch', async () => { process.env.CONDA_SHLVL = '1'; interpreterService .setup((i) => i.getInterpreterDetails(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ envName: 'base' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ envName: 'base' } as unknown as PythonEnvironment)); workspaceService.setup((w) => w.workspaceFile).returns(() => undefined); const workspaceFolder: WorkspaceFolder = { name: 'one', uri, index: 0 }; workspaceService.setup((w) => w.workspaceFolders).returns(() => [workspaceFolder]); @@ -409,9 +407,7 @@ suite('Activated Env Launch', async () => { processService .setup((p) => p.shellExec('conda config --get auto_activate_base')) .returns(() => - Promise.resolve(({ stdout: '--set auto_activate_base False' } as unknown) as ExecutionResult< - string - >), + Promise.resolve({ stdout: '--set auto_activate_base False' } as unknown as ExecutionResult), ); activatedEnvLaunch = new ActivatedEnvironmentLaunch( workspaceService.object, @@ -429,7 +425,7 @@ suite('Activated Env Launch', async () => { process.env.CONDA_SHLVL = '1'; interpreterService .setup((i) => i.getInterpreterDetails(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ envName: 'base' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ envName: 'base' } as unknown as PythonEnvironment)); workspaceService.setup((w) => w.workspaceFile).returns(() => undefined); const workspaceFolder: WorkspaceFolder = { name: 'one', uri, index: 0 }; workspaceService.setup((w) => w.workspaceFolders).returns(() => [workspaceFolder]); @@ -450,9 +446,7 @@ suite('Activated Env Launch', async () => { processService .setup((p) => p.shellExec('conda config --get auto_activate_base')) .returns(() => - Promise.resolve(({ stdout: '--set auto_activate_base False' } as unknown) as ExecutionResult< - string - >), + Promise.resolve({ stdout: '--set auto_activate_base False' } as unknown as ExecutionResult), ); activatedEnvLaunch = new ActivatedEnvironmentLaunch( workspaceService.object, @@ -470,7 +464,7 @@ suite('Activated Env Launch', async () => { process.env.CONDA_SHLVL = '1'; interpreterService .setup((i) => i.getInterpreterDetails(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ envName: 'base' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ envName: 'base' } as unknown as PythonEnvironment)); workspaceService.setup((w) => w.workspaceFile).returns(() => undefined); const workspaceFolder: WorkspaceFolder = { name: 'one', uri, index: 0 }; workspaceService.setup((w) => w.workspaceFolders).returns(() => [workspaceFolder]); @@ -481,9 +475,7 @@ suite('Activated Env Launch', async () => { processService .setup((p) => p.shellExec('conda config --get auto_activate_base')) .returns(() => - Promise.resolve(({ stdout: '--set auto_activate_base True' } as unknown) as ExecutionResult< - string - >), + Promise.resolve({ stdout: '--set auto_activate_base True' } as unknown as ExecutionResult), ); activatedEnvLaunch = new ActivatedEnvironmentLaunch( workspaceService.object, @@ -501,7 +493,7 @@ suite('Activated Env Launch', async () => { process.env.CONDA_SHLVL = '1'; interpreterService .setup((i) => i.getInterpreterDetails(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ envName: 'nonbase' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ envName: 'nonbase' } as unknown as PythonEnvironment)); workspaceService.setup((w) => w.workspaceFile).returns(() => undefined); const workspaceFolder: WorkspaceFolder = { name: 'one', uri, index: 0 }; workspaceService.setup((w) => w.workspaceFolders).returns(() => [workspaceFolder]); @@ -512,9 +504,7 @@ suite('Activated Env Launch', async () => { processService .setup((p) => p.shellExec('conda config --get auto_activate_base')) .returns(() => - Promise.resolve(({ stdout: '--set auto_activate_base False' } as unknown) as ExecutionResult< - string - >), + Promise.resolve({ stdout: '--set auto_activate_base False' } as unknown as ExecutionResult), ); activatedEnvLaunch = new ActivatedEnvironmentLaunch( workspaceService.object, @@ -530,7 +520,7 @@ suite('Activated Env Launch', async () => { test('Do not show prompt if conda environment is not activated', async () => { interpreterService .setup((i) => i.getInterpreterDetails(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ envName: 'base' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ envName: 'base' } as unknown as PythonEnvironment)); workspaceService.setup((w) => w.workspaceFile).returns(() => undefined); const workspaceFolder: WorkspaceFolder = { name: 'one', uri, index: 0 }; workspaceService.setup((w) => w.workspaceFolders).returns(() => [workspaceFolder]); @@ -541,9 +531,7 @@ suite('Activated Env Launch', async () => { processService .setup((p) => p.shellExec('conda config --get auto_activate_base')) .returns(() => - Promise.resolve(({ stdout: '--set auto_activate_base False' } as unknown) as ExecutionResult< - string - >), + Promise.resolve({ stdout: '--set auto_activate_base False' } as unknown as ExecutionResult), ); activatedEnvLaunch = new ActivatedEnvironmentLaunch( workspaceService.object, diff --git a/src/test/interpreters/virtualEnvs/virtualEnvPrompt.unit.test.ts b/src/test/interpreters/virtualEnvs/virtualEnvPrompt.unit.test.ts index 2ad67831c455..817a25bfe27f 100644 --- a/src/test/interpreters/virtualEnvs/virtualEnvPrompt.unit.test.ts +++ b/src/test/interpreters/virtualEnvs/virtualEnvPrompt.unit.test.ts @@ -47,10 +47,10 @@ suite('Virtual Environment Prompt', () => { interpreterService = mock(); isCreatingEnvironmentStub = sinon.stub(createEnvApi, 'isCreatingEnvironment'); isCreatingEnvironmentStub.returns(false); - when(interpreterService.getActiveInterpreter(anything())).thenResolve(({ + when(interpreterService.getActiveInterpreter(anything())).thenResolve({ id: 'selected', path: 'path/to/selected', - } as unknown) as PythonEnvironment); + } as unknown as PythonEnvironment); disposable = mock(Disposable); appShell = mock(ApplicationShell); environmentPrompt = new VirtualEnvironmentPromptTest( @@ -110,7 +110,7 @@ suite('Virtual Environment Prompt', () => { when(helper.getBestInterpreter(deepEqual([interpreter1, interpreter2] as any))).thenReturn(interpreter2 as any); reset(interpreterService); when(interpreterService.getActiveInterpreter(anything())).thenResolve( - (interpreter2 as unknown) as PythonEnvironment, + interpreter2 as unknown as PythonEnvironment, ); when(persistentStateFactory.createWorkspacePersistentState(anything(), true)).thenReturn( notificationPromptEnabled.object, diff --git a/src/test/languageServer/jediLSExtensionManager.unit.test.ts b/src/test/languageServer/jediLSExtensionManager.unit.test.ts index b57a0bbd096d..32deb3db0c96 100644 --- a/src/test/languageServer/jediLSExtensionManager.unit.test.ts +++ b/src/test/languageServer/jediLSExtensionManager.unit.test.ts @@ -24,11 +24,11 @@ suite('Language Server - Jedi LS extension manager', () => { {} as IInterpreterPathService, {} as IInterpreterService, {} as IEnvironmentVariablesProvider, - ({ + { registerCommand: () => { /* do nothing */ }, - } as unknown) as ICommandManager, + } as unknown as ICommandManager, ); }); @@ -38,9 +38,9 @@ suite('Language Server - Jedi LS extension manager', () => { }); test('canStartLanguageServer should return true if an interpreter is passed in', () => { - const result = manager.canStartLanguageServer(({ + const result = manager.canStartLanguageServer({ path: 'path/to/interpreter', - } as unknown) as PythonEnvironment); + } as unknown as PythonEnvironment); assert.strictEqual(result, true); }); diff --git a/src/test/languageServer/pylanceLSExtensionManager.unit.test.ts b/src/test/languageServer/pylanceLSExtensionManager.unit.test.ts index 751b26d37d3c..79e02223f8fa 100644 --- a/src/test/languageServer/pylanceLSExtensionManager.unit.test.ts +++ b/src/test/languageServer/pylanceLSExtensionManager.unit.test.ts @@ -29,11 +29,11 @@ suite('Language Server - Pylance LS extension manager', () => { {} as IInterpreterPathService, {} as IInterpreterService, {} as IEnvironmentVariablesProvider, - ({ + { registerCommand: () => { /** do nothing */ }, - } as unknown) as ICommandManager, + } as unknown as ICommandManager, {} as IFileSystem, {} as IExtensions, {} as IApplicationShell, @@ -55,15 +55,15 @@ suite('Language Server - Pylance LS extension manager', () => { {} as IInterpreterPathService, {} as IInterpreterService, {} as IEnvironmentVariablesProvider, - ({ + { registerCommand: () => { /** do nothing */ }, - } as unknown) as ICommandManager, + } as unknown as ICommandManager, {} as IFileSystem, - ({ + { getExtension: () => ({}), - } as unknown) as IExtensions, + } as unknown as IExtensions, {} as IApplicationShell, ); @@ -82,15 +82,15 @@ suite('Language Server - Pylance LS extension manager', () => { {} as IInterpreterPathService, {} as IInterpreterService, {} as IEnvironmentVariablesProvider, - ({ + { registerCommand: () => { /* do nothing */ }, - } as unknown) as ICommandManager, + } as unknown as ICommandManager, {} as IFileSystem, - ({ + { getExtension: () => undefined, - } as unknown) as IExtensions, + } as unknown as IExtensions, {} as IApplicationShell, ); diff --git a/src/test/languageServer/watcher.unit.test.ts b/src/test/languageServer/watcher.unit.test.ts index e86e19cf2055..42b17bec6109 100644 --- a/src/test/languageServer/watcher.unit.test.ts +++ b/src/test/languageServer/watcher.unit.test.ts @@ -42,22 +42,22 @@ suite('Language server watcher', () => { getSettings: () => ({ languageServer: LanguageServerType.None }), } as IConfigurationService, {} as IExperimentService, - ({ + { getActiveWorkspaceUri: () => undefined, - } as unknown) as IInterpreterHelper, - ({ + } as unknown as IInterpreterHelper, + { onDidChange: () => { /* do nothing */ }, - } as unknown) as IInterpreterPathService, - ({ + } as unknown as IInterpreterPathService, + { getActiveInterpreter: () => 'python', onDidChangeInterpreterInformation: () => { /* do nothing */ }, - } as unknown) as IInterpreterService, + } as unknown as IInterpreterService, {} as IEnvironmentVariablesProvider, - ({ + { getWorkspaceFolder: (uri: Uri) => ({ uri }), onDidChangeConfiguration: () => { /* do nothing */ @@ -65,19 +65,19 @@ suite('Language server watcher', () => { onDidChangeWorkspaceFolders: () => { /* do nothing */ }, - } as unknown) as IWorkspaceService, - ({ + } as unknown as IWorkspaceService, + { registerCommand: () => { /* do nothing */ }, - } as unknown) as ICommandManager, + } as unknown as ICommandManager, {} as IFileSystem, - ({ + { getExtension: () => undefined, onDidChange: () => { /* do nothing */ }, - } as unknown) as IExtensions, + } as unknown as IExtensions, {} as IApplicationShell, disposables, ); @@ -98,18 +98,18 @@ suite('Language server watcher', () => { } as IConfigurationService, {} as IExperimentService, {} as IInterpreterHelper, - ({ + { onDidChange: () => { /* do nothing */ }, - } as unknown) as IInterpreterPathService, - ({ + } as unknown as IInterpreterPathService, + { onDidChangeInterpreterInformation: () => { /* do nothing */ }, - } as unknown) as IInterpreterService, + } as unknown as IInterpreterService, {} as IEnvironmentVariablesProvider, - ({ + { isTrusted: true, getWorkspaceFolder: (uri: Uri) => ({ uri }), onDidChangeConfiguration: () => { @@ -118,15 +118,15 @@ suite('Language server watcher', () => { onDidChangeWorkspaceFolders: () => { /* do nothing */ }, - } as unknown) as IWorkspaceService, + } as unknown as IWorkspaceService, {} as ICommandManager, {} as IFileSystem, - ({ + { getExtension: () => undefined, onDidChange: () => { /* do nothing */ }, - } as unknown) as IExtensions, + } as unknown as IExtensions, {} as IApplicationShell, disposables, ); @@ -143,18 +143,18 @@ suite('Language server watcher', () => { } as IConfigurationService, {} as IExperimentService, {} as IInterpreterHelper, - ({ + { onDidChange: () => { /* do nothing */ }, - } as unknown) as IInterpreterPathService, - ({ + } as unknown as IInterpreterPathService, + { onDidChangeInterpreterInformation: () => { /* do nothing */ }, - } as unknown) as IInterpreterService, + } as unknown as IInterpreterService, {} as IEnvironmentVariablesProvider, - ({ + { isTrusted: false, getWorkspaceFolder: (uri: Uri) => ({ uri }), onDidChangeConfiguration: () => { @@ -163,15 +163,15 @@ suite('Language server watcher', () => { onDidChangeWorkspaceFolders: () => { /* do nothing */ }, - } as unknown) as IWorkspaceService, + } as unknown as IWorkspaceService, {} as ICommandManager, {} as IFileSystem, - ({ + { getExtension: () => undefined, onDidChange: () => { /* do nothing */ }, - } as unknown) as IExtensions, + } as unknown as IExtensions, {} as IApplicationShell, disposables, ); @@ -194,39 +194,39 @@ suite('Language server watcher', () => { getActiveInterpreterStub.onFirstCall().returns('python'); getActiveInterpreterStub.onSecondCall().returns('other/python'); - const interpreterService = ({ + const interpreterService = { getActiveInterpreter: getActiveInterpreterStub, onDidChangeInterpreterInformation: () => { /* do nothing */ }, - } as unknown) as IInterpreterService; + } as unknown as IInterpreterService; watcher = new LanguageServerWatcher( - ({ + { get: () => { /* do nothing */ }, - } as unknown) as IServiceContainer, + } as unknown as IServiceContainer, {} as ILanguageServerOutputChannel, { getSettings: () => ({ languageServer: LanguageServerType.None }), } as IConfigurationService, {} as IExperimentService, - ({ + { getActiveWorkspaceUri: () => undefined, - } as unknown) as IInterpreterHelper, - ({ + } as unknown as IInterpreterHelper, + { onDidChange: () => { /* do nothing */ }, - } as unknown) as IInterpreterPathService, + } as unknown as IInterpreterPathService, interpreterService, - ({ + { onDidEnvironmentVariablesChange: () => { /* do nothing */ }, - } as unknown) as IEnvironmentVariablesProvider, - ({ + } as unknown as IEnvironmentVariablesProvider, + { isTrusted: true, getWorkspaceFolder: (uri: Uri) => ({ uri }), onDidChangeConfiguration: () => { @@ -235,19 +235,19 @@ suite('Language server watcher', () => { onDidChangeWorkspaceFolders: () => { /* do nothing */ }, - } as unknown) as IWorkspaceService, - ({ + } as unknown as IWorkspaceService, + { registerCommand: () => { /* do nothing */ }, - } as unknown) as ICommandManager, + } as unknown as ICommandManager, {} as IFileSystem, - ({ + { getExtension: () => undefined, onDidChange: () => { /* do nothing */ }, - } as unknown) as IExtensions, + } as unknown as IExtensions, {} as IApplicationShell, disposables, ); @@ -288,22 +288,22 @@ suite('Language server watcher', () => { getSettings: () => ({ languageServer: LanguageServerType.None }), } as IConfigurationService, {} as IExperimentService, - ({ + { getActiveWorkspaceUri: () => ({ folderUri: Uri.parse('workspace') }), - } as unknown) as IInterpreterHelper, - ({ + } as unknown as IInterpreterHelper, + { onDidChange: () => { /* do nothing */ }, - } as unknown) as IInterpreterPathService, - ({ + } as unknown as IInterpreterPathService, + { getActiveInterpreter: () => 'python', onDidChangeInterpreterInformation: () => { /* do nothing */ }, - } as unknown) as IInterpreterService, + } as unknown as IInterpreterService, {} as IEnvironmentVariablesProvider, - ({ + { getWorkspaceFolder: (uri: Uri) => ({ uri }), onDidChangeConfiguration: () => { /* do nothing */ @@ -311,19 +311,19 @@ suite('Language server watcher', () => { onDidChangeWorkspaceFolders: () => { /* do nothing */ }, - } as unknown) as IWorkspaceService, - ({ + } as unknown as IWorkspaceService, + { registerCommand: () => { /* do nothing */ }, - } as unknown) as ICommandManager, + } as unknown as ICommandManager, {} as IFileSystem, - ({ + { getExtension: () => undefined, onDidChange: () => { /* do nothing */ }, - } as unknown) as IExtensions, + } as unknown as IExtensions, {} as IApplicationShell, disposables, ); @@ -358,7 +358,7 @@ suite('Language server watcher', () => { test('When the config settings change, but the python.languageServer setting is not affected, the watcher should not restart the language server', async () => { let onDidChangeConfigListener: (event: ConfigurationChangeEvent) => Promise = () => Promise.resolve(); - const workspaceService = ({ + const workspaceService = { getWorkspaceFolder: (uri: Uri) => ({ uri }), onDidChangeConfiguration: (listener: (event: ConfigurationChangeEvent) => Promise) => { onDidChangeConfigListener = listener; @@ -366,7 +366,7 @@ suite('Language server watcher', () => { onDidChangeWorkspaceFolders: () => { /* do nothing */ }, - } as unknown) as IWorkspaceService; + } as unknown as IWorkspaceService; watcher = new LanguageServerWatcher( {} as IServiceContainer, @@ -375,34 +375,34 @@ suite('Language server watcher', () => { getSettings: () => ({ languageServer: LanguageServerType.None }), } as IConfigurationService, {} as IExperimentService, - ({ + { getActiveWorkspaceUri: () => undefined, - } as unknown) as IInterpreterHelper, - ({ + } as unknown as IInterpreterHelper, + { onDidChange: () => { /* do nothing */ }, - } as unknown) as IInterpreterPathService, - ({ + } as unknown as IInterpreterPathService, + { getActiveInterpreter: () => 'python', onDidChangeInterpreterInformation: () => { /* do nothing */ }, - } as unknown) as IInterpreterService, + } as unknown as IInterpreterService, {} as IEnvironmentVariablesProvider, workspaceService, - ({ + { registerCommand: () => { /* do nothing */ }, - } as unknown) as ICommandManager, + } as unknown as ICommandManager, {} as IFileSystem, - ({ + { getExtension: () => undefined, onDidChange: () => { /* do nothing */ }, - } as unknown) as IExtensions, + } as unknown as IExtensions, {} as IApplicationShell, disposables, ); @@ -420,7 +420,7 @@ suite('Language server watcher', () => { test('When the config settings change, and the python.languageServer setting is affected, the watcher should restart the language server', async () => { let onDidChangeConfigListener: (event: ConfigurationChangeEvent) => Promise = () => Promise.resolve(); - const workspaceService = ({ + const workspaceService = { getWorkspaceFolder: (uri: Uri) => ({ uri }), onDidChangeConfiguration: (listener: (event: ConfigurationChangeEvent) => Promise) => { onDidChangeConfigListener = listener; @@ -429,49 +429,49 @@ suite('Language server watcher', () => { /* do nothing */ }, workspaceFolders: [{ uri: Uri.parse('workspace') }], - } as unknown) as IWorkspaceService; + } as unknown as IWorkspaceService; const getSettingsStub = sandbox.stub(); getSettingsStub.onFirstCall().returns({ languageServer: LanguageServerType.None }); getSettingsStub.onSecondCall().returns({ languageServer: LanguageServerType.Node }); - const configService = ({ + const configService = { getSettings: getSettingsStub, - } as unknown) as IConfigurationService; + } as unknown as IConfigurationService; watcher = new LanguageServerWatcher( {} as IServiceContainer, {} as ILanguageServerOutputChannel, configService, {} as IExperimentService, - ({ + { getActiveWorkspaceUri: () => undefined, - } as unknown) as IInterpreterHelper, - ({ + } as unknown as IInterpreterHelper, + { onDidChange: () => { /* do nothing */ }, - } as unknown) as IInterpreterPathService, - ({ + } as unknown as IInterpreterPathService, + { getActiveInterpreter: () => 'python', onDidChangeInterpreterInformation: () => { /* do nothing */ }, - } as unknown) as IInterpreterService, + } as unknown as IInterpreterService, {} as IEnvironmentVariablesProvider, workspaceService, - ({ + { registerCommand: () => { /* do nothing */ }, - } as unknown) as ICommandManager, + } as unknown as ICommandManager, {} as IFileSystem, - ({ + { getExtension: () => undefined, onDidChange: () => { /* do nothing */ }, - } as unknown) as IExtensions, + } as unknown as IExtensions, {} as IApplicationShell, disposables, ); @@ -499,22 +499,22 @@ suite('Language server watcher', () => { getSettings: () => ({ languageServer: LanguageServerType.Jedi }), } as IConfigurationService, {} as IExperimentService, - ({ + { getActiveWorkspaceUri: () => undefined, - } as unknown) as IInterpreterHelper, - ({ + } as unknown as IInterpreterHelper, + { onDidChange: () => { /* do nothing */ }, - } as unknown) as IInterpreterPathService, - ({ + } as unknown as IInterpreterPathService, + { getActiveInterpreter: () => ({ version: { major: 2, minor: 7 } }), onDidChangeInterpreterInformation: () => { /* do nothing */ }, - } as unknown) as IInterpreterService, + } as unknown as IInterpreterService, {} as IEnvironmentVariablesProvider, - ({ + { getWorkspaceFolder: (uri: Uri) => ({ uri }), onDidChangeConfiguration: () => { /* do nothing */ @@ -522,19 +522,19 @@ suite('Language server watcher', () => { onDidChangeWorkspaceFolders: () => { /* do nothing */ }, - } as unknown) as IWorkspaceService, - ({ + } as unknown as IWorkspaceService, + { registerCommand: () => { /* do nothing */ }, - } as unknown) as ICommandManager, + } as unknown as ICommandManager, {} as IFileSystem, - ({ + { getExtension: () => undefined, onDidChange: () => { /* do nothing */ }, - } as unknown) as IExtensions, + } as unknown as IExtensions, {} as IApplicationShell, disposables, ); @@ -560,22 +560,22 @@ suite('Language server watcher', () => { }), } as IConfigurationService, {} as IExperimentService, - ({ + { getActiveWorkspaceUri: () => undefined, - } as unknown) as IInterpreterHelper, - ({ + } as unknown as IInterpreterHelper, + { onDidChange: () => { /* do nothing */ }, - } as unknown) as IInterpreterPathService, - ({ + } as unknown as IInterpreterPathService, + { getActiveInterpreter: () => ({ version: { major: 2, minor: 7 } }), onDidChangeInterpreterInformation: () => { /* do nothing */ }, - } as unknown) as IInterpreterService, + } as unknown as IInterpreterService, {} as IEnvironmentVariablesProvider, - ({ + { getWorkspaceFolder: (uri: Uri) => ({ uri }), onDidChangeConfiguration: () => { /* do nothing */ @@ -583,22 +583,22 @@ suite('Language server watcher', () => { onDidChangeWorkspaceFolders: () => { /* do nothing */ }, - } as unknown) as IWorkspaceService, - ({ + } as unknown as IWorkspaceService, + { registerCommand: () => { /* do nothing */ }, - } as unknown) as ICommandManager, + } as unknown as ICommandManager, {} as IFileSystem, - ({ + { getExtension: () => undefined, onDidChange: () => { /* do nothing */ }, - } as unknown) as IExtensions, - ({ + } as unknown as IExtensions, + { showWarningMessage: () => Promise.resolve(undefined), - } as unknown) as IApplicationShell, + } as unknown as IApplicationShell, disposables, ); watcher.register(); @@ -619,22 +619,22 @@ suite('Language server watcher', () => { getSettings: () => ({ languageServer: LanguageServerType.Jedi }), } as IConfigurationService, {} as IExperimentService, - ({ + { getActiveWorkspaceUri: () => undefined, - } as unknown) as IInterpreterHelper, - ({ + } as unknown as IInterpreterHelper, + { onDidChange: () => { /* do nothing */ }, - } as unknown) as IInterpreterPathService, - ({ + } as unknown as IInterpreterPathService, + { getActiveInterpreter: () => ({ version: { major: 2, minor: 7 } }), onDidChangeInterpreterInformation: () => { /* do nothing */ }, - } as unknown) as IInterpreterService, + } as unknown as IInterpreterService, {} as IEnvironmentVariablesProvider, - ({ + { isTrusted: false, getWorkspaceFolder: (uri: Uri) => ({ uri }), onDidChangeConfiguration: () => { @@ -643,19 +643,19 @@ suite('Language server watcher', () => { onDidChangeWorkspaceFolders: () => { /* do nothing */ }, - } as unknown) as IWorkspaceService, - ({ + } as unknown as IWorkspaceService, + { registerCommand: () => { /* do nothing */ }, - } as unknown) as ICommandManager, + } as unknown as ICommandManager, {} as IFileSystem, - ({ + { getExtension: () => undefined, onDidChange: () => { /* do nothing */ }, - } as unknown) as IExtensions, + } as unknown as IExtensions, {} as IApplicationShell, disposables, ); @@ -706,22 +706,22 @@ suite('Language server watcher', () => { getSettings: () => ({ languageServer }), } as IConfigurationService, {} as IExperimentService, - ({ + { getActiveWorkspaceUri: () => undefined, - } as unknown) as IInterpreterHelper, - ({ + } as unknown as IInterpreterHelper, + { onDidChange: () => { /* do nothing */ }, - } as unknown) as IInterpreterPathService, - ({ + } as unknown as IInterpreterPathService, + { getActiveInterpreter: getActiveInterpreterStub, onDidChangeInterpreterInformation: () => { /* do nothing */ }, - } as unknown) as IInterpreterService, + } as unknown as IInterpreterService, {} as IEnvironmentVariablesProvider, - ({ + { isTrusted: true, getWorkspaceFolder: (uri: Uri) => ({ uri }), onDidChangeConfiguration: () => { @@ -730,22 +730,22 @@ suite('Language server watcher', () => { onDidChangeWorkspaceFolders: () => { /* do nothing */ }, - } as unknown) as IWorkspaceService, - ({ + } as unknown as IWorkspaceService, + { registerCommand: () => { /* do nothing */ }, - } as unknown) as ICommandManager, + } as unknown as ICommandManager, {} as IFileSystem, - ({ + { getExtension: () => undefined, onDidChange: () => { /* do nothing */ }, - } as unknown) as IExtensions, - ({ + } as unknown as IExtensions, + { showWarningMessage: () => Promise.resolve(undefined), - } as unknown) as IApplicationShell, + } as unknown as IApplicationShell, disposables, ); watcher.register(); @@ -775,7 +775,7 @@ suite('Language server watcher', () => { let onDidChangeWorkspaceFoldersListener: (event: WorkspaceFoldersChangeEvent) => Promise = () => Promise.resolve(); - const workspaceService = ({ + const workspaceService = { getWorkspaceFolder: (uri: Uri) => ({ uri }), onDidChangeConfiguration: () => { /* do nothing */ @@ -785,7 +785,7 @@ suite('Language server watcher', () => { }, workspaceFolders: [{ uri: Uri.parse('workspace1') }, { uri: Uri.parse('workspace2') }], isTrusted: true, - } as unknown) as IWorkspaceService; + } as unknown as IWorkspaceService; watcher = new LanguageServerWatcher( {} as IServiceContainer, @@ -794,37 +794,37 @@ suite('Language server watcher', () => { getSettings: () => ({ languageServer }), } as IConfigurationService, {} as IExperimentService, - ({ + { getActiveWorkspaceUri: () => undefined, - } as unknown) as IInterpreterHelper, - ({ + } as unknown as IInterpreterHelper, + { onDidChange: () => { /* do nothing */ }, - } as unknown) as IInterpreterPathService, - ({ + } as unknown as IInterpreterPathService, + { getActiveInterpreter: () => ({ version: { major: 3, minor: 7 } }), onDidChangeInterpreterInformation: () => { /* do nothing */ }, - } as unknown) as IInterpreterService, + } as unknown as IInterpreterService, {} as IEnvironmentVariablesProvider, workspaceService, - ({ + { registerCommand: () => { /* do nothing */ }, - } as unknown) as ICommandManager, + } as unknown as ICommandManager, {} as IFileSystem, - ({ + { getExtension: () => undefined, onDidChange: () => { /* do nothing */ }, - } as unknown) as IExtensions, - ({ + } as unknown as IExtensions, + { showWarningMessage: () => Promise.resolve(undefined), - } as unknown) as IApplicationShell, + } as unknown as IApplicationShell, disposables, ); watcher.register(); @@ -845,14 +845,14 @@ suite('Language server watcher', () => { }); test('The language server should be restarted if the interpreter info changed', async () => { - const info = ({ + const info = { envPath: 'foo', path: 'path/to/foo/bin/python', - } as unknown) as PythonEnvironment; + } as unknown as PythonEnvironment; let onDidChangeInfoListener: (event: PythonEnvironment) => Promise = () => Promise.resolve(); - const interpreterService = ({ + const interpreterService = { onDidChangeInterpreterInformation: ( listener: (event: PythonEnvironment) => Promise, thisArg: unknown, @@ -863,34 +863,34 @@ suite('Language server watcher', () => { envPath: 'foo', path: 'path/to/foo', }), - } as unknown) as IInterpreterService; + } as unknown as IInterpreterService; watcher = new LanguageServerWatcher( - ({ + { get: () => { /* do nothing */ }, - } as unknown) as IServiceContainer, + } as unknown as IServiceContainer, {} as ILanguageServerOutputChannel, { getSettings: () => ({ languageServer: LanguageServerType.None }), } as IConfigurationService, {} as IExperimentService, - ({ + { getActiveWorkspaceUri: () => undefined, - } as unknown) as IInterpreterHelper, - ({ + } as unknown as IInterpreterHelper, + { onDidChange: () => { /* do nothing */ }, - } as unknown) as IInterpreterPathService, + } as unknown as IInterpreterPathService, interpreterService, - ({ + { onDidEnvironmentVariablesChange: () => { /* do nothing */ }, - } as unknown) as IEnvironmentVariablesProvider, - ({ + } as unknown as IEnvironmentVariablesProvider, + { isTrusted: true, getWorkspaceFolder: (uri: Uri) => ({ uri }), onDidChangeConfiguration: () => { @@ -899,19 +899,19 @@ suite('Language server watcher', () => { onDidChangeWorkspaceFolders: () => { /* do nothing */ }, - } as unknown) as IWorkspaceService, - ({ + } as unknown as IWorkspaceService, + { registerCommand: () => { /* do nothing */ }, - } as unknown) as ICommandManager, + } as unknown as ICommandManager, {} as IFileSystem, - ({ + { getExtension: () => undefined, onDidChange: () => { /* do nothing */ }, - } as unknown) as IExtensions, + } as unknown as IExtensions, {} as IApplicationShell, disposables, ); @@ -928,14 +928,14 @@ suite('Language server watcher', () => { }); test('The language server should not be restarted if the interpreter info did not change', async () => { - const info = ({ + const info = { envPath: 'foo', path: 'path/to/foo', - } as unknown) as PythonEnvironment; + } as unknown as PythonEnvironment; let onDidChangeInfoListener: (event: PythonEnvironment) => Promise = () => Promise.resolve(); - const interpreterService = ({ + const interpreterService = { onDidChangeInterpreterInformation: ( listener: (event: PythonEnvironment) => Promise, thisArg: unknown, @@ -943,34 +943,34 @@ suite('Language server watcher', () => { onDidChangeInfoListener = listener.bind(thisArg); }, getActiveInterpreter: () => info, - } as unknown) as IInterpreterService; + } as unknown as IInterpreterService; watcher = new LanguageServerWatcher( - ({ + { get: () => { /* do nothing */ }, - } as unknown) as IServiceContainer, + } as unknown as IServiceContainer, {} as ILanguageServerOutputChannel, { getSettings: () => ({ languageServer: LanguageServerType.None }), } as IConfigurationService, {} as IExperimentService, - ({ + { getActiveWorkspaceUri: () => undefined, - } as unknown) as IInterpreterHelper, - ({ + } as unknown as IInterpreterHelper, + { onDidChange: () => { /* do nothing */ }, - } as unknown) as IInterpreterPathService, + } as unknown as IInterpreterPathService, interpreterService, - ({ + { onDidEnvironmentVariablesChange: () => { /* do nothing */ }, - } as unknown) as IEnvironmentVariablesProvider, - ({ + } as unknown as IEnvironmentVariablesProvider, + { isTrusted: true, getWorkspaceFolder: (uri: Uri) => ({ uri }), onDidChangeConfiguration: () => { @@ -979,19 +979,19 @@ suite('Language server watcher', () => { onDidChangeWorkspaceFolders: () => { /* do nothing */ }, - } as unknown) as IWorkspaceService, - ({ + } as unknown as IWorkspaceService, + { registerCommand: () => { /* do nothing */ }, - } as unknown) as ICommandManager, + } as unknown as ICommandManager, {} as IFileSystem, - ({ + { getExtension: () => undefined, onDidChange: () => { /* do nothing */ }, - } as unknown) as IExtensions, + } as unknown as IExtensions, {} as IApplicationShell, disposables, ); @@ -1008,14 +1008,14 @@ suite('Language server watcher', () => { }); test('The language server should not be restarted if the interpreter info changed but the env path is an empty string', async () => { - const info = ({ + const info = { envPath: '', path: 'path/to/foo', - } as unknown) as PythonEnvironment; + } as unknown as PythonEnvironment; let onDidChangeInfoListener: (event: PythonEnvironment) => Promise = () => Promise.resolve(); - const interpreterService = ({ + const interpreterService = { onDidChangeInterpreterInformation: ( listener: (event: PythonEnvironment) => Promise, thisArg: unknown, @@ -1026,34 +1026,34 @@ suite('Language server watcher', () => { envPath: 'foo', path: 'path/to/foo', }), - } as unknown) as IInterpreterService; + } as unknown as IInterpreterService; watcher = new LanguageServerWatcher( - ({ + { get: () => { /* do nothing */ }, - } as unknown) as IServiceContainer, + } as unknown as IServiceContainer, {} as ILanguageServerOutputChannel, { getSettings: () => ({ languageServer: LanguageServerType.None }), } as IConfigurationService, {} as IExperimentService, - ({ + { getActiveWorkspaceUri: () => undefined, - } as unknown) as IInterpreterHelper, - ({ + } as unknown as IInterpreterHelper, + { onDidChange: () => { /* do nothing */ }, - } as unknown) as IInterpreterPathService, + } as unknown as IInterpreterPathService, interpreterService, - ({ + { onDidEnvironmentVariablesChange: () => { /* do nothing */ }, - } as unknown) as IEnvironmentVariablesProvider, - ({ + } as unknown as IEnvironmentVariablesProvider, + { isTrusted: true, getWorkspaceFolder: (uri: Uri) => ({ uri }), onDidChangeConfiguration: () => { @@ -1062,19 +1062,19 @@ suite('Language server watcher', () => { onDidChangeWorkspaceFolders: () => { /* do nothing */ }, - } as unknown) as IWorkspaceService, - ({ + } as unknown as IWorkspaceService, + { registerCommand: () => { /* do nothing */ }, - } as unknown) as ICommandManager, + } as unknown as ICommandManager, {} as IFileSystem, - ({ + { getExtension: () => undefined, onDidChange: () => { /* do nothing */ }, - } as unknown) as IExtensions, + } as unknown as IExtensions, {} as IApplicationShell, disposables, ); @@ -1091,14 +1091,14 @@ suite('Language server watcher', () => { }); test('The language server should not be restarted if the interpreter info changed but the env path is undefined', async () => { - const info = ({ + const info = { envPath: undefined, path: 'path/to/foo', - } as unknown) as PythonEnvironment; + } as unknown as PythonEnvironment; let onDidChangeInfoListener: (event: PythonEnvironment) => Promise = () => Promise.resolve(); - const interpreterService = ({ + const interpreterService = { onDidChangeInterpreterInformation: ( listener: (event: PythonEnvironment) => Promise, thisArg: unknown, @@ -1109,34 +1109,34 @@ suite('Language server watcher', () => { envPath: 'foo', path: 'path/to/foo', }), - } as unknown) as IInterpreterService; + } as unknown as IInterpreterService; watcher = new LanguageServerWatcher( - ({ + { get: () => { /* do nothing */ }, - } as unknown) as IServiceContainer, + } as unknown as IServiceContainer, {} as ILanguageServerOutputChannel, { getSettings: () => ({ languageServer: LanguageServerType.None }), } as IConfigurationService, {} as IExperimentService, - ({ + { getActiveWorkspaceUri: () => undefined, - } as unknown) as IInterpreterHelper, - ({ + } as unknown as IInterpreterHelper, + { onDidChange: () => { /* do nothing */ }, - } as unknown) as IInterpreterPathService, + } as unknown as IInterpreterPathService, interpreterService, - ({ + { onDidEnvironmentVariablesChange: () => { /* do nothing */ }, - } as unknown) as IEnvironmentVariablesProvider, - ({ + } as unknown as IEnvironmentVariablesProvider, + { isTrusted: true, getWorkspaceFolder: (uri: Uri) => ({ uri }), onDidChangeConfiguration: () => { @@ -1145,19 +1145,19 @@ suite('Language server watcher', () => { onDidChangeWorkspaceFolders: () => { /* do nothing */ }, - } as unknown) as IWorkspaceService, - ({ + } as unknown as IWorkspaceService, + { registerCommand: () => { /* do nothing */ }, - } as unknown) as ICommandManager, + } as unknown as ICommandManager, {} as IFileSystem, - ({ + { getExtension: () => undefined, onDidChange: () => { /* do nothing */ }, - } as unknown) as IExtensions, + } as unknown as IExtensions, {} as IApplicationShell, disposables, ); diff --git a/src/test/mocks/autoSelector.ts b/src/test/mocks/autoSelector.ts index cc4ab4ddb8e5..efc25b227a12 100644 --- a/src/test/mocks/autoSelector.ts +++ b/src/test/mocks/autoSelector.ts @@ -14,7 +14,8 @@ import { PythonEnvironment } from '../../client/pythonEnvironments/info'; @injectable() export class MockAutoSelectionService - implements IInterpreterAutoSelectionService, IInterpreterAutoSelectionProxyService { + implements IInterpreterAutoSelectionService, IInterpreterAutoSelectionProxyService +{ // eslint-disable-next-line class-methods-use-this public async setWorkspaceInterpreter(_resource: Resource, _interpreter: PythonEnvironment): Promise { return Promise.resolve(); diff --git a/src/test/mocks/vsc/arrays.ts b/src/test/mocks/vsc/arrays.ts index ad2020c57110..ebbbe707f716 100644 --- a/src/test/mocks/vsc/arrays.ts +++ b/src/test/mocks/vsc/arrays.ts @@ -364,7 +364,7 @@ export function index(array: T[], indexer: (t: T) => string, merger?: (t: export function index( array: T[], indexer: (t: T) => string, - merger: (t: T, r: R) => R = (t) => (t as unknown) as R, + merger: (t: T, r: R) => R = (t) => t as unknown as R, ): Record { return array.reduce((r, t) => { const key = indexer(t); diff --git a/src/test/mocks/vsc/extHostedTypes.ts b/src/test/mocks/vsc/extHostedTypes.ts index f87b50174150..2288352525f1 100644 --- a/src/test/mocks/vsc/extHostedTypes.ts +++ b/src/test/mocks/vsc/extHostedTypes.ts @@ -450,12 +450,12 @@ export class Selection extends Range { } toJSON(): [Position, Position] { - return ({ + return { start: this.start, end: this.end, active: this.active, anchor: this.anchor, - } as unknown) as [Position, Position]; + } as unknown as [Position, Position]; } } @@ -648,7 +648,7 @@ export class WorkspaceEdit implements vscode.WorkspaceEdit { set(uri: vscUri.URI, edits: readonly unknown[]): void { let data = this._textEdits.get(uri.toString()); if (!data) { - data = { seq: this._seqPool += 1, uri, edits: [] }; + data = { seq: (this._seqPool += 1), uri, edits: [] }; this._textEdits.set(uri.toString(), data); } if (!edits) { @@ -884,7 +884,7 @@ export class Diagnostic { toJSON(): { severity: DiagnosticSeverity; message: string; range: Range; source: string; code: string | number } { return { - severity: (DiagnosticSeverity[this.severity] as unknown) as DiagnosticSeverity, + severity: DiagnosticSeverity[this.severity] as unknown as DiagnosticSeverity, message: this.message, range: this.range, source: this.source, @@ -933,7 +933,7 @@ export class DocumentHighlight { toJSON(): { range: Range; kind: DocumentHighlightKind } { return { range: this.range, - kind: (DocumentHighlightKind[this.kind] as unknown) as DocumentHighlightKind, + kind: DocumentHighlightKind[this.kind] as unknown as DocumentHighlightKind, }; } } @@ -1008,7 +1008,7 @@ export class SymbolInformation { toJSON(): { name: string; kind: SymbolKind; location: Location; containerName: string } { return { name: this.name, - kind: (SymbolKind[this.kind] as unknown) as SymbolKind, + kind: SymbolKind[this.kind] as unknown as SymbolKind, location: this.location, containerName: this.containerName, }; @@ -1269,7 +1269,7 @@ export class CompletionItem { return { label: this.label, label2: this.label2, - kind: this.kind && ((CompletionItemKind[this.kind] as unknown) as CompletionItemKind), + kind: this.kind && (CompletionItemKind[this.kind] as unknown as CompletionItemKind), detail: this.detail, documentation: this.documentation, sortText: this.sortText, diff --git a/src/test/mocks/vsc/index.ts b/src/test/mocks/vsc/index.ts index 152beb64cdf4..99c855a58d2d 100644 --- a/src/test/mocks/vsc/index.ts +++ b/src/test/mocks/vsc/index.ts @@ -125,7 +125,7 @@ export class EventEmitter implements vscode.EventEmitter { public emitter: NodeEventEmitter; constructor() { - this.event = (this.add.bind(this) as unknown) as vscode.Event; + this.event = this.add.bind(this) as unknown as vscode.Event; this.emitter = new NodeEventEmitter(); } diff --git a/src/test/proc.ts b/src/test/proc.ts index 8a21eb379f76..b3653d5dfd3f 100644 --- a/src/test/proc.ts +++ b/src/test/proc.ts @@ -51,7 +51,7 @@ export class Proc { private readonly output: ProcOutput; private result: ProcResult | undefined; constructor(raw: cp.ChildProcess, output: ProcOutput) { - this.raw = (raw as unknown) as IRawProc; + this.raw = raw as unknown as IRawProc; this.output = output; } public get pid(): number | undefined { diff --git a/src/test/providers/codeActionProvider/main.unit.test.ts b/src/test/providers/codeActionProvider/main.unit.test.ts index 55644d80ae54..227c162f2ae4 100644 --- a/src/test/providers/codeActionProvider/main.unit.test.ts +++ b/src/test/providers/codeActionProvider/main.unit.test.ts @@ -48,7 +48,7 @@ suite('Code Action Provider service', async () => { pattern: '**/launch.json', }); assert.deepEqual(metadata!, { - providedCodeActionKinds: [('CodeAction' as unknown) as CodeActionKind], + providedCodeActionKinds: ['CodeAction' as unknown as CodeActionKind], }); expect(provider!).instanceOf(LaunchJsonCodeActionProvider); }); diff --git a/src/test/providers/repl.unit.test.ts b/src/test/providers/repl.unit.test.ts index 72adfa95a4a0..f42ad40099df 100644 --- a/src/test/providers/repl.unit.test.ts +++ b/src/test/providers/repl.unit.test.ts @@ -43,7 +43,7 @@ suite('REPL Provider', () => { interpreterService = TypeMoq.Mock.ofType(); interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: 'ps' } as unknown as PythonEnvironment)); serviceContainer.setup((c) => c.get(IInterpreterService)).returns(() => interpreterService.object); }); teardown(() => { diff --git a/src/test/pythonEnvironments/base/info/environmentInfoService.functional.test.ts b/src/test/pythonEnvironments/base/info/environmentInfoService.functional.test.ts index 785148f8589c..d7ce4182b535 100644 --- a/src/test/pythonEnvironments/base/info/environmentInfoService.functional.test.ts +++ b/src/test/pythonEnvironments/base/info/environmentInfoService.functional.test.ts @@ -45,8 +45,7 @@ suite('Environment Info Service', () => { stubShellExec.returns( new Promise>((resolve) => { resolve({ - stdout: - '{"versionInfo": [3, 8, 3, "final", 0], "sysPrefix": "path", "sysVersion": "3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)]", "is64Bit": true}', + stdout: '{"versionInfo": [3, 8, 3, "final", 0], "sysPrefix": "path", "sysVersion": "3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)]", "is64Bit": true}', stderr: 'Some std error', // This should be ignored. }); }), diff --git a/src/test/pythonEnvironments/base/locatorUtils.unit.test.ts b/src/test/pythonEnvironments/base/locatorUtils.unit.test.ts index 8e4bc02e4797..c726c7f7c52c 100644 --- a/src/test/pythonEnvironments/base/locatorUtils.unit.test.ts +++ b/src/test/pythonEnvironments/base/locatorUtils.unit.test.ts @@ -87,14 +87,16 @@ suite('Python envs locator utils - getQueryFilter', () => { assert.deepEqual(filtered, []); }); - ([ - [PythonEnvKind.Unknown, [env3]], - [PythonEnvKind.System, [env1, env5]], - [PythonEnvKind.MicrosoftStore, []], - [PythonEnvKind.Pyenv, [env2, env4]], - [PythonEnvKind.Venv, [envL1, envSL1, envSL5]], - [PythonEnvKind.Conda, [env6, envL2, envSL3]], - ] as [PythonEnvKind, PythonEnvInfo[]][]).forEach(([kind, expected]) => { + ( + [ + [PythonEnvKind.Unknown, [env3]], + [PythonEnvKind.System, [env1, env5]], + [PythonEnvKind.MicrosoftStore, []], + [PythonEnvKind.Pyenv, [env2, env4]], + [PythonEnvKind.Venv, [envL1, envSL1, envSL5]], + [PythonEnvKind.Conda, [env6, envL2, envSL3]], + ] as [PythonEnvKind, PythonEnvInfo[]][] + ).forEach(([kind, expected]) => { test(`match some (one kind: ${kind})`, () => { const query: PythonLocatorQuery = { kinds: [kind] }; diff --git a/src/test/pythonEnvironments/base/locators/composite/envsResolver.unit.test.ts b/src/test/pythonEnvironments/base/locators/composite/envsResolver.unit.test.ts index 0d189da35282..3ebbf23ac426 100644 --- a/src/test/pythonEnvironments/base/locators/composite/envsResolver.unit.test.ts +++ b/src/test/pythonEnvironments/base/locators/composite/envsResolver.unit.test.ts @@ -120,8 +120,7 @@ suite('Python envs locator - Environments Resolver', () => { stubShellExec.returns( new Promise>((resolve) => { resolve({ - stdout: - '{"versionInfo": [3, 8, 3, "final", 0], "sysPrefix": "path", "sysVersion": "3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)]", "is64Bit": true}', + stdout: '{"versionInfo": [3, 8, 3, "final", 0], "sysPrefix": "path", "sysVersion": "3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)]", "is64Bit": true}', }); }), ); @@ -269,8 +268,7 @@ suite('Python envs locator - Environments Resolver', () => { () => new Promise>((resolve) => { resolve({ - stdout: - '{"versionInfo": [3, 8, 3, "final", 0], "sysPrefix": "path", "sysVersion": "3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)]", "is64Bit": true}', + stdout: '{"versionInfo": [3, 8, 3, "final", 0], "sysPrefix": "path", "sysVersion": "3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)]", "is64Bit": true}', }); }), ), @@ -363,8 +361,7 @@ suite('Python envs locator - Environments Resolver', () => { stubShellExec.returns( new Promise>((resolve) => { resolve({ - stdout: - '{"versionInfo": [3, 8, 3, "final", 0], "sysPrefix": "path", "sysVersion": "3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)]", "is64Bit": true}', + stdout: '{"versionInfo": [3, 8, 3, "final", 0], "sysPrefix": "path", "sysVersion": "3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)]", "is64Bit": true}', }); }), ); diff --git a/src/test/pythonEnvironments/common/environmentManagers/conda.unit.test.ts b/src/test/pythonEnvironments/common/environmentManagers/conda.unit.test.ts index 9480dffe6a59..2f9deb9fbb4a 100644 --- a/src/test/pythonEnvironments/common/environmentManagers/conda.unit.test.ts +++ b/src/test/pythonEnvironments/common/environmentManagers/conda.unit.test.ts @@ -140,7 +140,7 @@ suite('Conda and its environments are located correctly', () => { } if (options === undefined) { - return (Object.keys(getFile(filePath, 'throwIfMissing')) as unknown) as fs.Dirent[]; + return Object.keys(getFile(filePath, 'throwIfMissing')) as unknown as fs.Dirent[]; } const names = Object.keys(dir); @@ -148,23 +148,21 @@ suite('Conda and its environments are located correctly', () => { return names; } - return names.map( - (name): fs.Dirent => { - const isFile = typeof dir[name] === 'string'; - return { - name, - path: dir.name?.toString() ?? '', - isFile: () => isFile, - isDirectory: () => !isFile, - isBlockDevice: () => false, - isCharacterDevice: () => false, - isSymbolicLink: () => false, - isFIFO: () => false, - isSocket: () => false, - parentPath: '', - }; - }, - ); + return names.map((name): fs.Dirent => { + const isFile = typeof dir[name] === 'string'; + return { + name, + path: dir.name?.toString() ?? '', + isFile: () => isFile, + isDirectory: () => !isFile, + isBlockDevice: () => false, + isCharacterDevice: () => false, + isSymbolicLink: () => false, + isFIFO: () => false, + isSocket: () => false, + parentPath: '', + }; + }); }, ); const readFileStub = async ( diff --git a/src/test/pythonEnvironments/creation/common/installCheckUtils.unit.test.ts b/src/test/pythonEnvironments/creation/common/installCheckUtils.unit.test.ts index 2900b9b89c8f..a71fd16f7433 100644 --- a/src/test/pythonEnvironments/creation/common/installCheckUtils.unit.test.ts +++ b/src/test/pythonEnvironments/creation/common/installCheckUtils.unit.test.ts @@ -49,7 +49,7 @@ suite('Install check diagnostics tests', () => { interpreterService = typemoq.Mock.ofType(); interpreterService .setup((i) => i.getActiveInterpreter(typemoq.It.isAny())) - .returns(() => Promise.resolve(({ path: 'python' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: 'python' } as unknown as PythonEnvironment)); getConfigurationStub = sinon.stub(workspaceApis, 'getConfiguration'); getConfigurationStub.callsFake((section?: string, _scope?: ConfigurationScope | null) => { if (section === 'python') { diff --git a/src/test/pythonEnvironments/creation/globalPipInTerminalTrigger.unit.test.ts b/src/test/pythonEnvironments/creation/globalPipInTerminalTrigger.unit.test.ts index 2b6a8df91d82..0f57db871096 100644 --- a/src/test/pythonEnvironments/creation/globalPipInTerminalTrigger.unit.test.ts +++ b/src/test/pythonEnvironments/creation/globalPipInTerminalTrigger.unit.test.ts @@ -76,7 +76,7 @@ suite('Global Pip in Terminal Trigger', () => { execEvent.setup((e) => e.shellIntegration).returns(() => shellIntegration.object); shellIntegration .setup((s) => s.executeCommand(typemoq.It.isAnyString())) - .returns(() => (({} as unknown) as TerminalShellExecution)); + .returns(() => ({} as unknown as TerminalShellExecution)); }); teardown(() => { @@ -113,7 +113,7 @@ suite('Global Pip in Terminal Trigger', () => { registerTriggerForPipInTerminal(disposables); shellIntegration.setup((s) => s.cwd).returns(() => outsideWorkspace); - await handler?.(({ shellIntegration: shellIntegration.object } as unknown) as TerminalShellExecutionStartEvent); + await handler?.({ shellIntegration: shellIntegration.object } as unknown as TerminalShellExecutionStartEvent); assert.strictEqual(disposables.length, 1); sinon.assert.calledOnce(shouldPromptToCreateEnvStub); @@ -129,7 +129,7 @@ suite('Global Pip in Terminal Trigger', () => { const disposables: Disposable[] = []; registerTriggerForPipInTerminal(disposables); - await handler?.(({ shellIntegration: shellIntegration.object } as unknown) as TerminalShellExecutionStartEvent); + await handler?.({ shellIntegration: shellIntegration.object } as unknown as TerminalShellExecutionStartEvent); assert.strictEqual(disposables.length, 1); sinon.assert.calledOnce(shouldPromptToCreateEnvStub); @@ -147,7 +147,7 @@ suite('Global Pip in Terminal Trigger', () => { registerTriggerForPipInTerminal(disposables); await handler?.({ - terminal: ({} as unknown) as Terminal, + terminal: {} as unknown as Terminal, shellIntegration: shellIntegration.object, execution: { cwd: workspace1.uri, @@ -179,7 +179,7 @@ suite('Global Pip in Terminal Trigger', () => { registerTriggerForPipInTerminal(disposables); await handler?.({ - terminal: ({} as unknown) as Terminal, + terminal: {} as unknown as Terminal, shellIntegration: shellIntegration.object, execution: { cwd: workspace1.uri, @@ -213,7 +213,7 @@ suite('Global Pip in Terminal Trigger', () => { registerTriggerForPipInTerminal(disposables); await handler?.({ - terminal: ({} as unknown) as Terminal, + terminal: {} as unknown as Terminal, shellIntegration: shellIntegration.object, execution: { cwd: workspace1.uri, @@ -251,7 +251,7 @@ suite('Global Pip in Terminal Trigger', () => { registerTriggerForPipInTerminal(disposables); await handler?.({ - terminal: ({} as unknown) as Terminal, + terminal: {} as unknown as Terminal, shellIntegration: shellIntegration.object, execution: { cwd: workspace1.uri, diff --git a/src/test/repl/nativeRepl.test.ts b/src/test/repl/nativeRepl.test.ts index 999bc656c64d..e970f7cbf931 100644 --- a/src/test/repl/nativeRepl.test.ts +++ b/src/test/repl/nativeRepl.test.ts @@ -24,7 +24,7 @@ suite('REPL - Native REPL', () => { interpreterService = TypeMoq.Mock.ofType(); interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: 'ps' } as unknown as PythonEnvironment)); disposable = TypeMoq.Mock.ofType(); disposableArray = [disposable.object]; @@ -48,7 +48,7 @@ suite('REPL - Native REPL', () => { const createMethodStub = sinon.stub(NativeRepl, 'create'); interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: 'ps' } as unknown as PythonEnvironment)); const interpreter = await interpreterService.object.getActiveInterpreter(); await getNativeRepl(interpreter as PythonEnvironment, disposableArray); @@ -59,7 +59,7 @@ suite('REPL - Native REPL', () => { getWorkspaceStateValueStub = sinon.stub(persistentState, 'getWorkspaceStateValue').returns(undefined); interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: 'ps' } as unknown as PythonEnvironment)); const interpreter = await interpreterService.object.getActiveInterpreter(); const nativeRepl = await getNativeRepl(interpreter as PythonEnvironment, disposableArray); @@ -72,7 +72,7 @@ suite('REPL - Native REPL', () => { getWorkspaceStateValueStub = sinon.stub(persistentState, 'getWorkspaceStateValue').returns('myNameIsMemento'); interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: 'ps' } as unknown as PythonEnvironment)); const interpreter = await interpreterService.object.getActiveInterpreter(); const nativeRepl = await getNativeRepl(interpreter as PythonEnvironment, disposableArray); @@ -85,7 +85,7 @@ suite('REPL - Native REPL', () => { const interpreter = await interpreterService.object.getActiveInterpreter(); interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: 'ps' } as unknown as PythonEnvironment)); await NativeRepl.create(interpreter as PythonEnvironment); diff --git a/src/test/repl/replCommand.test.ts b/src/test/repl/replCommand.test.ts index 7c26ebd69c80..ee4358b7d72d 100644 --- a/src/test/repl/replCommand.test.ts +++ b/src/test/repl/replCommand.test.ts @@ -56,7 +56,7 @@ suite('REPL - register native repl command', () => { test('Ensure repl command is registered', async () => { interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: 'ps' } as unknown as PythonEnvironment)); await replCommands.registerReplCommands( disposableArray, @@ -74,7 +74,7 @@ suite('REPL - register native repl command', () => { test('Ensure getSendToNativeREPLSetting is called', async () => { interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: 'ps' } as unknown as PythonEnvironment)); let commandHandler: undefined | (() => Promise); commandManager @@ -105,7 +105,7 @@ suite('REPL - register native repl command', () => { test('Ensure executeInTerminal is called when getSendToNativeREPLSetting returns false', async () => { interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: 'ps' } as unknown as PythonEnvironment)); getSendToNativeREPLSettingStub.returns(false); let commandHandler: undefined | (() => Promise); @@ -137,7 +137,7 @@ suite('REPL - register native repl command', () => { test('Ensure we call getNativeREPL() when interpreter exist', async () => { interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: 'ps' } as unknown as PythonEnvironment)); getSendToNativeREPLSettingStub.returns(true); getNativeReplStub = sinon.stub(nativeRepl, 'getNativeRepl'); diff --git a/src/test/terminals/activation.unit.test.ts b/src/test/terminals/activation.unit.test.ts index dea0c891229d..97898e7da6ba 100644 --- a/src/test/terminals/activation.unit.test.ts +++ b/src/test/terminals/activation.unit.test.ts @@ -37,7 +37,7 @@ suite('Terminal', () => { instance(resourceService), ); - terminal = ({ + terminal = { dispose: noop, hide: noop, name: 'Some Name', @@ -46,8 +46,8 @@ suite('Terminal', () => { sendText: noop, show: noop, exitStatus: { code: 0 }, - } as unknown) as Terminal; - nonActivatedTerminal = ({ + } as unknown as Terminal; + nonActivatedTerminal = { dispose: noop, hide: noop, creationOptions: { hideFromUser: true }, @@ -56,7 +56,7 @@ suite('Terminal', () => { sendText: noop, show: noop, exitStatus: { code: 0 }, - } as unknown) as Terminal; + } as unknown as Terminal; autoActivation.register(); }); // teardown(() => fakeTimer.uninstall()); @@ -64,7 +64,7 @@ suite('Terminal', () => { test('Should activate terminal', async () => { // Trigger opening a terminal. - await ((onDidOpenTerminalEventEmitter.fire(terminal) as unknown) as Promise); + await (onDidOpenTerminalEventEmitter.fire(terminal) as unknown as Promise); // The terminal should get activated. verify(activator.activateEnvironmentInTerminal(terminal, anything())).once(); @@ -72,7 +72,7 @@ suite('Terminal', () => { test('Should not activate terminal if name starts with specific prefix', async () => { // Trigger opening a terminal. - await ((onDidOpenTerminalEventEmitter.fire(nonActivatedTerminal) as unknown) as Promise); + await (onDidOpenTerminalEventEmitter.fire(nonActivatedTerminal) as unknown as Promise); // The terminal should get activated. verify(activator.activateEnvironmentInTerminal(anything(), anything())).never(); diff --git a/src/test/terminals/codeExecution/codeExecutionManager.unit.test.ts b/src/test/terminals/codeExecution/codeExecutionManager.unit.test.ts index 726b118ce180..f8408f9afb60 100644 --- a/src/test/terminals/codeExecution/codeExecutionManager.unit.test.ts +++ b/src/test/terminals/codeExecution/codeExecutionManager.unit.test.ts @@ -46,7 +46,7 @@ suite('Terminal - Code Execution Manager', () => { interpreterService = TypeMoq.Mock.ofType(); interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: 'ps' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: 'ps' } as unknown as PythonEnvironment)); serviceContainer.setup((c) => c.get(IInterpreterService)).returns(() => interpreterService.object); executionManager = new CodeExecutionManager( commandManager.object, diff --git a/src/test/terminals/codeExecution/djangoShellCodeExect.unit.test.ts b/src/test/terminals/codeExecution/djangoShellCodeExect.unit.test.ts index 749d94672765..6e823c7c4897 100644 --- a/src/test/terminals/codeExecution/djangoShellCodeExect.unit.test.ts +++ b/src/test/terminals/codeExecution/djangoShellCodeExect.unit.test.ts @@ -100,7 +100,7 @@ suite('Terminal - Django Shell Code Execution', () => { platform.setup((p) => p.isWindows).returns(() => isWindows); interpreterService .setup((s) => s.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: pythonPath } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: pythonPath } as unknown as PythonEnvironment)); terminalSettings.setup((t) => t.launchArgs).returns(() => terminalArgs); const replCommandArgs = await (executor as DjangoShellCodeExecutionProvider).getExecutableInfo(resource); @@ -221,7 +221,7 @@ suite('Terminal - Django Shell Code Execution', () => { ) { interpreterService .setup((s) => s.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: pythonPath } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: pythonPath } as unknown as PythonEnvironment)); terminalSettings.setup((t) => t.launchArgs).returns(() => terminalArgs); const condaFile = 'conda'; diff --git a/src/test/terminals/codeExecution/helper.test.ts b/src/test/terminals/codeExecution/helper.test.ts index a43c5f8746ed..063f038ed0c0 100644 --- a/src/test/terminals/codeExecution/helper.test.ts +++ b/src/test/terminals/codeExecution/helper.test.ts @@ -205,7 +205,7 @@ suite('Terminal - Code Execution Helper', async () => { .setup((p) => p.execObservable(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())) .returns((_, args: string[]) => { execArgs = args.join(' '); - return ({} as unknown) as ObservableExecutionResult; + return {} as unknown as ObservableExecutionResult; }); await helper.normalizeLines('print("hello")', ReplType.terminal); diff --git a/src/test/terminals/codeExecution/terminalCodeExec.unit.test.ts b/src/test/terminals/codeExecution/terminalCodeExec.unit.test.ts index b5bcecd971ea..cad9cdb5ceb2 100644 --- a/src/test/terminals/codeExecution/terminalCodeExec.unit.test.ts +++ b/src/test/terminals/codeExecution/terminalCodeExec.unit.test.ts @@ -161,7 +161,7 @@ suite('Terminal - Code Execution', () => { platform.setup((p) => p.isLinux).returns(() => isLinux); interpreterService .setup((s) => s.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: PYTHON_PATH } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: PYTHON_PATH } as unknown as PythonEnvironment)); terminalSettings.setup((t) => t.launchArgs).returns(() => []); await executor.initializeRepl(); @@ -196,7 +196,7 @@ suite('Terminal - Code Execution', () => { platform.setup((p) => p.isWindows).returns(() => true); interpreterService .setup((s) => s.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: PYTHON_PATH } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: PYTHON_PATH } as unknown as PythonEnvironment)); terminalSettings.setup((t) => t.launchArgs).returns(() => []); await executor.executeFile(file); @@ -223,7 +223,7 @@ suite('Terminal - Code Execution', () => { platform.setup((p) => p.isWindows).returns(() => true); interpreterService .setup((s) => s.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: PYTHON_PATH } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: PYTHON_PATH } as unknown as PythonEnvironment)); terminalSettings.setup((t) => t.launchArgs).returns(() => []); await executor.executeFile(file); @@ -241,7 +241,7 @@ suite('Terminal - Code Execution', () => { platform.setup((p) => p.isWindows).returns(() => false); interpreterService .setup((s) => s.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: PYTHON_PATH } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: PYTHON_PATH } as unknown as PythonEnvironment)); terminalSettings.setup((t) => t.launchArgs).returns(() => []); await executor.executeFile(file); @@ -269,7 +269,7 @@ suite('Terminal - Code Execution', () => { platform.setup((p) => p.isWindows).returns(() => isWindows); interpreterService .setup((s) => s.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: PYTHON_PATH } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: PYTHON_PATH } as unknown as PythonEnvironment)); terminalSettings.setup((t) => t.launchArgs).returns(() => []); await executor.executeFile(file); @@ -297,7 +297,7 @@ suite('Terminal - Code Execution', () => { platform.setup((p) => p.isWindows).returns(() => isWindows); interpreterService .setup((s) => s.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: PYTHON_PATH } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: PYTHON_PATH } as unknown as PythonEnvironment)); terminalSettings.setup((t) => t.launchArgs).returns(() => []); await executor.executeFile(file); @@ -320,7 +320,7 @@ suite('Terminal - Code Execution', () => { platform.setup((p) => p.isWindows).returns(() => isWindows); interpreterService .setup((s) => s.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: PYTHON_PATH } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: PYTHON_PATH } as unknown as PythonEnvironment)); terminalSettings.setup((t) => t.launchArgs).returns(() => []); await executor.executeFile(file); @@ -343,7 +343,7 @@ suite('Terminal - Code Execution', () => { platform.setup((p) => p.isWindows).returns(() => isWindows); interpreterService .setup((s) => s.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: pythonPath } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: pythonPath } as unknown as PythonEnvironment)); terminalSettings.setup((t) => t.launchArgs).returns(() => terminalArgs); terminalSettings.setup((t) => t.executeInFileDir).returns(() => false); workspace.setup((w) => w.getWorkspaceFolder(TypeMoq.It.isAny())).returns(() => undefined); @@ -389,7 +389,7 @@ suite('Terminal - Code Execution', () => { ): Promise { interpreterService .setup((s) => s.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: pythonPath } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: pythonPath } as unknown as PythonEnvironment)); terminalSettings.setup((t) => t.launchArgs).returns(() => terminalArgs); terminalSettings.setup((t) => t.executeInFileDir).returns(() => false); workspace.setup((w) => w.getWorkspaceFolder(TypeMoq.It.isAny())).returns(() => undefined); @@ -459,7 +459,7 @@ suite('Terminal - Code Execution', () => { platform.setup((p) => p.isWindows).returns(() => isWindows); interpreterService .setup((s) => s.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: pythonPath } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: pythonPath } as unknown as PythonEnvironment)); terminalSettings.setup((t) => t.launchArgs).returns(() => terminalArgs); const expectedTerminalArgs = isDjangoRepl ? terminalArgs.concat(['manage.py', 'shell']) : terminalArgs; @@ -511,7 +511,7 @@ suite('Terminal - Code Execution', () => { ) { interpreterService .setup((s) => s.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: pythonPath } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: pythonPath } as unknown as PythonEnvironment)); terminalSettings.setup((t) => t.launchArgs).returns(() => terminalArgs); const condaFile = 'conda'; @@ -569,7 +569,7 @@ suite('Terminal - Code Execution', () => { await executor.execute(''); await executor.execute(' '); - await executor.execute((undefined as any) as string); + await executor.execute(undefined as any as string); terminalService.verify( async (t) => t.sendCommand(TypeMoq.It.isAny(), TypeMoq.It.isAny()), @@ -585,7 +585,7 @@ suite('Terminal - Code Execution', () => { platform.setup((p) => p.isWindows).returns(() => false); interpreterService .setup((s) => s.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: pythonPath } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: pythonPath } as unknown as PythonEnvironment)); terminalSettings.setup((t) => t.launchArgs).returns(() => terminalArgs); await executor.execute('cmd1'); @@ -606,7 +606,7 @@ suite('Terminal - Code Execution', () => { platform.setup((p) => p.isWindows).returns(() => false); interpreterService .setup((s) => s.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: pythonPath } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: pythonPath } as unknown as PythonEnvironment)); terminalSettings.setup((t) => t.launchArgs).returns(() => terminalArgs); await executor.execute('cmd1'); @@ -639,7 +639,7 @@ suite('Terminal - Code Execution', () => { platform.setup((p) => p.isWindows).returns(() => false); interpreterService .setup((s) => s.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: pythonPath } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: pythonPath } as unknown as PythonEnvironment)); terminalSettings.setup((t) => t.launchArgs).returns(() => terminalArgs); await executor.execute('cmd1'); @@ -664,7 +664,7 @@ suite('Terminal - Code Execution', () => { platform.setup((p) => p.isWindows).returns(() => false); interpreterService .setup((s) => s.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: pythonPath } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: pythonPath } as unknown as PythonEnvironment)); terminalSettings.setup((t) => t.launchArgs).returns(() => terminalArgs); await executor.execute('cmd1', resource); diff --git a/src/test/terminals/serviceRegistry.unit.test.ts b/src/test/terminals/serviceRegistry.unit.test.ts index 4f865cdedc0d..a734c4e379cd 100644 --- a/src/test/terminals/serviceRegistry.unit.test.ts +++ b/src/test/terminals/serviceRegistry.unit.test.ts @@ -57,7 +57,7 @@ suite('Terminal - Service Registry', () => { typemoq.It.is((v: any) => args[0] === v), typemoq.It.is((value: any) => args[1] === value), - typemoq.It.isValue((args[2] as unknown) as string), + typemoq.It.isValue(args[2] as unknown as string), ), ) .verifiable(typemoq.Times.once()); diff --git a/src/test/testBootstrap.ts b/src/test/testBootstrap.ts index ab902255203b..d33dd44f0f12 100644 --- a/src/test/testBootstrap.ts +++ b/src/test/testBootstrap.ts @@ -88,16 +88,13 @@ async function startSocketServer() { }); }); - server.listen( - { host: '127.0.0.1', port: 0 }, - async (): Promise => { - const port = (server!.address() as AddressInfo).port; - console.log(`Test server listening on port ${port}`); - await deletePortFile(); - await fs.writeFile(portFile, port.toString()); - resolve(); - }, - ); + server.listen({ host: '127.0.0.1', port: 0 }, async (): Promise => { + const port = (server!.address() as AddressInfo).port; + console.log(`Test server listening on port ${port}`); + await deletePortFile(); + await fs.writeFile(portFile, port.toString()); + resolve(); + }); server.on('error', (ex) => { // Just log it, no need to do anything else. console.error(ex); diff --git a/src/test/testing/common/debugLauncher.unit.test.ts b/src/test/testing/common/debugLauncher.unit.test.ts index 397ae03eafc2..d6316dec7060 100644 --- a/src/test/testing/common/debugLauncher.unit.test.ts +++ b/src/test/testing/common/debugLauncher.unit.test.ts @@ -112,7 +112,7 @@ suite('Unit Tests - Debug Launcher', () => { ) { interpreterService .setup((i) => i.getActiveInterpreter(TypeMoq.It.isAny())) - .returns(() => Promise.resolve(({ path: 'python' } as unknown) as PythonEnvironment)); + .returns(() => Promise.resolve({ path: 'python' } as unknown as PythonEnvironment)); settings.setup((p) => p.envFile).returns(() => __filename); const args = expected.args; const debugArgs = testProvider === 'unittest' ? args.filter((item: string) => item !== '--debug') : args; diff --git a/src/test/testing/common/testingAdapter.test.ts b/src/test/testing/common/testingAdapter.test.ts index ec19ce00f13f..f428700b3f69 100644 --- a/src/test/testing/common/testingAdapter.test.ts +++ b/src/test/testing/common/testingAdapter.test.ts @@ -355,11 +355,13 @@ suite('End to End Tests: test adapters', () => { traceLog('windows machine detected, converting path to lowercase for comparison'); const a = actualData.cwd.toLowerCase(); const b = filePath.toLowerCase(); - const testSimpleActual = (actualData.tests as { - children: { - path: string; - }[]; - }).children[0].path.toLowerCase(); + const testSimpleActual = ( + actualData.tests as { + children: { + path: string; + }[]; + } + ).children[0].path.toLowerCase(); const testSimpleExpected = filePath.toLowerCase(); assert.strictEqual(a, b, `Expected cwd to be the symlink path actual: ${a} expected: ${b}`); assert.strictEqual( @@ -374,11 +376,13 @@ suite('End to End Tests: test adapters', () => { 'Expected cwd to be the symlink path, check for non-windows machines', ); assert.strictEqual( - (actualData.tests as { - children: { - path: string; - }[]; - }).children[0].path, + ( + actualData.tests as { + children: { + path: string; + }[]; + } + ).children[0].path, filePath, 'Expected test path to be the symlink path, check for non windows machines', ); @@ -444,11 +448,13 @@ suite('End to End Tests: test adapters', () => { traceLog('windows machine detected, converting path to lowercase for comparison'); const a = actualData.cwd.toLowerCase(); const b = rootPathDiscoverySymlink.toLowerCase(); - const testSimpleActual = (actualData.tests as { - children: { - path: string; - }[]; - }).children[0].path.toLowerCase(); + const testSimpleActual = ( + actualData.tests as { + children: { + path: string; + }[]; + } + ).children[0].path.toLowerCase(); const testSimpleExpected = testSimpleSymlinkPath.toLowerCase(); assert.strictEqual(a, b, `Expected cwd to be the symlink path actual: ${a} expected: ${b}`); assert.strictEqual( @@ -463,11 +469,13 @@ suite('End to End Tests: test adapters', () => { 'Expected cwd to be the symlink path, check for non-windows machines', ); assert.strictEqual( - (actualData.tests as { - children: { - path: string; - }[]; - }).children[0].path, + ( + actualData.tests as { + children: { + path: string; + }[]; + } + ).children[0].path, testSimpleSymlinkPath, 'Expected test path to be the symlink path, check for non windows machines', ); diff --git a/src/test/testing/configuration.unit.test.ts b/src/test/testing/configuration.unit.test.ts index 6682abf019b8..5579c422ba9b 100644 --- a/src/test/testing/configuration.unit.test.ts +++ b/src/test/testing/configuration.unit.test.ts @@ -498,7 +498,7 @@ suite('Unit Tests - ConfigurationService', () => { .setup((c) => c.enable()) .returns(() => Promise.resolve()) .verifiable(typeMoq.Times.once()); - const configManagersToVerify: typeof configMgr[] = [configMgr]; + const configManagersToVerify: (typeof configMgr)[] = [configMgr]; await testConfigService.target.promptToEnableAndConfigureTestFramework(workspaceUri); diff --git a/src/test/testing/testController/pytest/pytestDiscoveryAdapter.unit.test.ts b/src/test/testing/testController/pytest/pytestDiscoveryAdapter.unit.test.ts index 157134cdf276..3a653ca9f6de 100644 --- a/src/test/testing/testController/pytest/pytestDiscoveryAdapter.unit.test.ts +++ b/src/test/testing/testController/pytest/pytestDiscoveryAdapter.unit.test.ts @@ -61,16 +61,16 @@ suite('pytest test discovery adapter', () => { }; // set up config service - configService = ({ + configService = { getSettings: () => ({ testing: { pytestArgs: ['.'] }, }), - } as unknown) as IConfigurationService; + } as unknown as IConfigurationService; // set up exec service with child process mockProc = new MockChildProcess('', ['']); execService = typeMoq.Mock.ofType(); - execService.setup((p) => ((p as unknown) as any).then).returns(() => undefined); + execService.setup((p) => (p as unknown as any).then).returns(() => undefined); execService.setup((x) => x.getExecutablePath()).returns(() => Promise.resolve('/mock/path/to/python')); outputChannel = typeMoq.Mock.ofType(); @@ -147,14 +147,14 @@ suite('pytest test discovery adapter', () => { test('Test discovery correctly pulls pytest args from config service settings', async () => { // set up a config service with different pytest args const expectedPathNew = path.join('other', 'path'); - const configServiceNew: IConfigurationService = ({ + const configServiceNew: IConfigurationService = { getSettings: () => ({ testing: { pytestArgs: ['.', 'abc', 'xyz'], cwd: expectedPathNew, }, }), - } as unknown) as IConfigurationService; + } as unknown as IConfigurationService; sinon.stub(fs.promises, 'lstat').callsFake( async () => @@ -220,14 +220,14 @@ suite('pytest test discovery adapter', () => { sinon.stub(fs.promises, 'realpath').callsFake(async (pathEntered) => pathEntered.toString()); // set up a config service with different pytest args - const configServiceNew: IConfigurationService = ({ + const configServiceNew: IConfigurationService = { getSettings: () => ({ testing: { pytestArgs: ['.', 'abc', 'xyz'], cwd: expectedPath, }, }), - } as unknown) as IConfigurationService; + } as unknown as IConfigurationService; // set up exec mock deferred = createDeferred(); @@ -288,14 +288,14 @@ suite('pytest test discovery adapter', () => { sinon.stub(fs.promises, 'realpath').callsFake(async () => 'diff value'); // set up a config service with different pytest args - const configServiceNew: IConfigurationService = ({ + const configServiceNew: IConfigurationService = { getSettings: () => ({ testing: { pytestArgs: ['.', 'abc', 'xyz'], cwd: expectedPath, }, }), - } as unknown) as IConfigurationService; + } as unknown as IConfigurationService; // set up exec mock deferred = createDeferred(); @@ -373,7 +373,7 @@ suite('pytest test discovery adapter', () => { test('Test discovery cancelled while exec observable is running and proc is closed', async () => { // const execService2 = typeMoq.Mock.ofType(); - execService2.setup((p) => ((p as unknown) as any).then).returns(() => undefined); + execService2.setup((p) => (p as unknown as any).then).returns(() => undefined); execService2 .setup((x) => x.execObservable(typeMoq.It.isAny(), typeMoq.It.isAny())) .returns(() => { diff --git a/src/test/testing/testController/pytest/pytestExecutionAdapter.unit.test.ts b/src/test/testing/testController/pytest/pytestExecutionAdapter.unit.test.ts index 413c0af9406d..109a2595124f 100644 --- a/src/test/testing/testController/pytest/pytestExecutionAdapter.unit.test.ts +++ b/src/test/testing/testController/pytest/pytestExecutionAdapter.unit.test.ts @@ -41,12 +41,12 @@ suite('pytest test execution adapter', () => { setup(() => { useEnvExtensionStub = sinon.stub(extapi, 'useEnvExtension'); useEnvExtensionStub.returns(false); - configService = ({ + configService = { getSettings: () => ({ testing: { pytestArgs: ['.'] }, }), isTestExecution: () => false, - } as unknown) as IConfigurationService; + } as unknown as IConfigurationService; // set up exec service with child process mockProc = new MockChildProcess('', ['']); @@ -82,9 +82,9 @@ suite('pytest test execution adapter', () => { deferred.resolve(); return Promise.resolve({ stdout: '{}' }); }); - execFactory.setup((p) => ((p as unknown) as any).then).returns(() => undefined); - execService.setup((p) => ((p as unknown) as any).then).returns(() => undefined); - debugLauncher.setup((p) => ((p as unknown) as any).then).returns(() => undefined); + execFactory.setup((p) => (p as unknown as any).then).returns(() => undefined); + execService.setup((p) => (p as unknown as any).then).returns(() => undefined); + debugLauncher.setup((p) => (p as unknown as any).then).returns(() => undefined); myTestPath = path.join('/', 'my', 'test', 'path', '/'); utilsStartRunResultNamedPipeStub = sinon.stub(util, 'startRunResultNamedPipe'); @@ -200,12 +200,12 @@ suite('pytest test execution adapter', () => { const testRun = typeMoq.Mock.ofType(); testRun.setup((t) => t.token).returns(() => ({ onCancellationRequested: () => undefined } as any)); const newCwd = path.join('new', 'path'); - configService = ({ + configService = { getSettings: () => ({ testing: { pytestArgs: ['.'], cwd: newCwd }, }), isTestExecution: () => false, - } as unknown) as IConfigurationService; + } as unknown as IConfigurationService; const uri = Uri.file(myTestPath); const outputChannel = typeMoq.Mock.ofType(); adapter = new PytestTestExecutionAdapter(configService, outputChannel.object); diff --git a/src/test/testing/testController/resultResolver.unit.test.ts b/src/test/testing/testController/resultResolver.unit.test.ts index 05d2ee1dd0f3..cf38e24e9fb1 100644 --- a/src/test/testing/testController/resultResolver.unit.test.ts +++ b/src/test/testing/testController/resultResolver.unit.test.ts @@ -28,7 +28,7 @@ suite('Result Resolver tests', () => { let cancelationToken: CancellationToken; setup(() => { - testController = ({ + testController = { items: { get: () => { log.push('get'); @@ -47,9 +47,9 @@ suite('Result Resolver tests', () => { dispose: () => { // empty }, - } as unknown) as TestController; + } as unknown as TestController; defaultErrorMessage = 'pytest test discovery error (see Output > Python)'; - blankTestItem = ({ + blankTestItem = { canResolveChildren: false, tags: [], children: { @@ -57,10 +57,10 @@ suite('Result Resolver tests', () => { // empty }, }, - } as unknown) as TestItem; - cancelationToken = ({ + } as unknown as TestItem; + cancelationToken = { isCancellationRequested: false, - } as unknown) as CancellationToken; + } as unknown as CancellationToken; }); teardown(() => { sinon.restore(); @@ -293,9 +293,9 @@ suite('Result Resolver tests', () => { testControllerMock = typemoq.Mock.ofType(); testControllerMock.setup((t) => t.items).returns(() => testItemCollectionMock.object); - cancelationToken = ({ + cancelationToken = { isCancellationRequested: false, - } as unknown) as CancellationToken; + } as unknown as CancellationToken; // define functions within runInstance runInstance = typemoq.Mock.ofType(); @@ -563,7 +563,7 @@ suite('Result Resolver tests', () => { function createMockTestItem(id: string): TestItem { const range = new Range(0, 0, 0, 0); - const mockTestItem = ({ + const mockTestItem = { id, canResolveChildren: false, tags: [], @@ -574,7 +574,7 @@ function createMockTestItem(id: string): TestItem { }, range, uri: Uri.file('/foo/bar'), - } as unknown) as TestItem; + } as unknown as TestItem; return mockTestItem; } diff --git a/src/test/testing/testController/testCancellationRunAdapters.unit.test.ts b/src/test/testing/testController/testCancellationRunAdapters.unit.test.ts index 81480d08b2b8..6ce6f7dd3f9e 100644 --- a/src/test/testing/testController/testCancellationRunAdapters.unit.test.ts +++ b/src/test/testing/testController/testCancellationRunAdapters.unit.test.ts @@ -40,12 +40,12 @@ suite('Execution Flow Run Adapters', () => { useEnvExtensionStub.returns(false); // general vars myTestPath = path.join('/', 'my', 'test', 'path', '/'); - configService = ({ + configService = { getSettings: () => ({ testing: { pytestArgs: ['.'], unittestArgs: ['-v', '-s', '.', '-p', 'test*'] }, }), isTestExecution: () => false, - } as unknown) as IConfigurationService; + } as unknown as IConfigurationService; // set up execService and execFactory, all mocked execServiceStub = typeMoq.Mock.ofType(); @@ -58,7 +58,7 @@ suite('Execution Flow Run Adapters', () => { // debug specific mocks debugLauncher = typeMoq.Mock.ofType(); - debugLauncher.setup((p) => ((p as unknown) as any).then).returns(() => undefined); + debugLauncher.setup((p) => (p as unknown as any).then).returns(() => undefined); }); teardown(() => { sinon.restore(); @@ -90,8 +90,8 @@ suite('Execution Flow Run Adapters', () => { execFactoryStub .setup((x) => x.createActivatedEnvironment(typeMoq.It.isAny())) .returns(() => Promise.resolve(execServiceStub.object)); - execFactoryStub.setup((p) => ((p as unknown) as any).then).returns(() => undefined); - execServiceStub.setup((p) => ((p as unknown) as any).then).returns(() => undefined); + execFactoryStub.setup((p) => (p as unknown as any).then).returns(() => undefined); + execServiceStub.setup((p) => (p as unknown as any).then).returns(() => undefined); // test ids named pipe mocking const deferredStartTestIdsNamedPipe = createDeferred(); @@ -159,8 +159,8 @@ suite('Execution Flow Run Adapters', () => { execFactoryStub .setup((x) => x.createActivatedEnvironment(typeMoq.It.isAny())) .returns(() => Promise.resolve(execServiceStub.object)); - execFactoryStub.setup((p) => ((p as unknown) as any).then).returns(() => undefined); - execServiceStub.setup((p) => ((p as unknown) as any).then).returns(() => undefined); + execFactoryStub.setup((p) => (p as unknown as any).then).returns(() => undefined); + execServiceStub.setup((p) => (p as unknown as any).then).returns(() => undefined); // test ids named pipe mocking const deferredStartTestIdsNamedPipe = createDeferred(); diff --git a/src/test/testing/testController/unittest/testDiscoveryAdapter.unit.test.ts b/src/test/testing/testController/unittest/testDiscoveryAdapter.unit.test.ts index 0a2cfad866d5..43678a269015 100644 --- a/src/test/testing/testController/unittest/testDiscoveryAdapter.unit.test.ts +++ b/src/test/testing/testController/unittest/testDiscoveryAdapter.unit.test.ts @@ -42,11 +42,11 @@ suite('Unittest test discovery adapter', () => { useEnvExtensionStub.returns(false); expectedPath = path.join('/', 'new', 'cwd'); - configService = ({ + configService = { getSettings: () => ({ testing: { unittestArgs: ['-v', '-s', '.', '-p', 'test*'] }, }), - } as unknown) as IConfigurationService; + } as unknown as IConfigurationService; outputChannel = typeMoq.Mock.ofType(); // set up exec service with child process @@ -74,8 +74,8 @@ suite('Unittest test discovery adapter', () => { execFactory .setup((x) => x.createActivatedEnvironment(typeMoq.It.isAny())) .returns(() => Promise.resolve(execService.object)); - execFactory.setup((p) => ((p as unknown) as any).then).returns(() => undefined); - execService.setup((p) => ((p as unknown) as any).then).returns(() => undefined); + execFactory.setup((p) => (p as unknown as any).then).returns(() => undefined); + execService.setup((p) => (p as unknown as any).then).returns(() => undefined); // constants expectedPath = path.join('/', 'my', 'test', 'path'); @@ -132,11 +132,11 @@ suite('Unittest test discovery adapter', () => { }); test('DiscoverTests should respect settings.testings.cwd when present', async () => { const expectedNewPath = path.join('/', 'new', 'cwd'); - configService = ({ + configService = { getSettings: () => ({ testing: { unittestArgs: ['-v', '-s', '.', '-p', 'test*'], cwd: expectedNewPath.toString() }, }), - } as unknown) as IConfigurationService; + } as unknown as IConfigurationService; const adapter = new UnittestTestDiscoveryAdapter(configService, outputChannel.object); adapter.discoverTests(uri, execFactory.object); const script = path.join(EXTENSION_ROOT_DIR, 'python_files', 'unittestadapter', 'discovery.py'); @@ -206,7 +206,7 @@ suite('Unittest test discovery adapter', () => { test('Test discovery cancelled while exec observable is running and proc is closed', async () => { // const execService2 = typeMoq.Mock.ofType(); - execService2.setup((p) => ((p as unknown) as any).then).returns(() => undefined); + execService2.setup((p) => (p as unknown as any).then).returns(() => undefined); execService2 .setup((x) => x.execObservable(typeMoq.It.isAny(), typeMoq.It.isAny())) .returns(() => { diff --git a/src/test/testing/testController/unittest/testExecutionAdapter.unit.test.ts b/src/test/testing/testController/unittest/testExecutionAdapter.unit.test.ts index 688d6d398101..6d181073ed2f 100644 --- a/src/test/testing/testController/unittest/testExecutionAdapter.unit.test.ts +++ b/src/test/testing/testController/unittest/testExecutionAdapter.unit.test.ts @@ -40,12 +40,12 @@ suite('Unittest test execution adapter', () => { setup(() => { useEnvExtensionStub = sinon.stub(extapi, 'useEnvExtension'); useEnvExtensionStub.returns(false); - configService = ({ + configService = { getSettings: () => ({ testing: { unittestArgs: ['.'] }, }), isTestExecution: () => false, - } as unknown) as IConfigurationService; + } as unknown as IConfigurationService; // set up exec service with child process mockProc = new MockChildProcess('', ['']); @@ -81,9 +81,9 @@ suite('Unittest test execution adapter', () => { deferred.resolve(); return Promise.resolve({ stdout: '{}' }); }); - execFactory.setup((p) => ((p as unknown) as any).then).returns(() => undefined); - execService.setup((p) => ((p as unknown) as any).then).returns(() => undefined); - debugLauncher.setup((p) => ((p as unknown) as any).then).returns(() => undefined); + execFactory.setup((p) => (p as unknown as any).then).returns(() => undefined); + execService.setup((p) => (p as unknown as any).then).returns(() => undefined); + debugLauncher.setup((p) => (p as unknown as any).then).returns(() => undefined); myTestPath = path.join('/', 'my', 'test', 'path', '/'); utilsStartRunResultNamedPipeStub = sinon.stub(util, 'startRunResultNamedPipe'); @@ -198,12 +198,12 @@ suite('Unittest test execution adapter', () => { const testRun = typeMoq.Mock.ofType(); testRun.setup((t) => t.token).returns(() => ({ onCancellationRequested: () => undefined } as any)); const newCwd = path.join('new', 'path'); - configService = ({ + configService = { getSettings: () => ({ testing: { unittestArgs: ['.'], cwd: newCwd }, }), isTestExecution: () => false, - } as unknown) as IConfigurationService; + } as unknown as IConfigurationService; const uri = Uri.file(myTestPath); const outputChannel = typeMoq.Mock.ofType(); adapter = new UnittestTestExecutionAdapter(configService, outputChannel.object); diff --git a/src/test/testing/testController/workspaceTestAdapter.unit.test.ts b/src/test/testing/testController/workspaceTestAdapter.unit.test.ts index 9a07d4451e85..6549c4d21a11 100644 --- a/src/test/testing/testController/workspaceTestAdapter.unit.test.ts +++ b/src/test/testing/testController/workspaceTestAdapter.unit.test.ts @@ -35,20 +35,20 @@ suite('Workspace test adapter', () => { let log: string[] = []; setup(() => { - stubConfigSettings = ({ + stubConfigSettings = { getSettings: () => ({ testing: { unittestArgs: ['--foo'] }, }), - } as unknown) as IConfigurationService; + } as unknown as IConfigurationService; - stubResultResolver = ({ + stubResultResolver = { resolveDiscovery: () => { // no body }, resolveExecution: () => { // no body }, - } as unknown) as ITestResultResolver; + } as unknown as ITestResultResolver; // const vsIdToRunIdGetStub = sinon.stub(stubResultResolver.vsIdToRunId, 'get'); // const expectedRunId = 'expectedRunId'; @@ -57,7 +57,7 @@ suite('Workspace test adapter', () => { // For some reason the 'tests' namespace in vscode returns undefined. // While I figure out how to expose to the tests, they will run // against a stub test controller and stub test items. - const testItem = ({ + const testItem = { canResolveChildren: false, tags: [], children: { @@ -65,9 +65,9 @@ suite('Workspace test adapter', () => { // empty }, }, - } as unknown) as TestItem; + } as unknown as TestItem; - testController = ({ + testController = { items: { get: () => { log.push('get'); @@ -89,7 +89,7 @@ suite('Workspace test adapter', () => { dispose: () => { // empty }, - } as unknown) as TestController; + } as unknown as TestController; // testController = tests.createTestController('mock-python-tests', 'Mock Python Tests'); @@ -130,7 +130,7 @@ suite('Workspace test adapter', () => { stubResultResolver, ); - const blankTestItem = ({ + const blankTestItem = { canResolveChildren: false, tags: [], children: { @@ -138,7 +138,7 @@ suite('Workspace test adapter', () => { // empty }, }, - } as unknown) as TestItem; + } as unknown as TestItem; const errorTestItemOptions: testItemUtilities.ErrorTestItemOptions = { id: 'id', label: 'label', @@ -267,13 +267,13 @@ suite('Workspace test adapter', () => { const sandbox = sinon.createSandbox(); setup(() => { - stubConfigSettings = ({ + stubConfigSettings = { getSettings: () => ({ testing: { unittestArgs: ['--foo'] }, }), - } as unknown) as IConfigurationService; + } as unknown as IConfigurationService; - stubResultResolver = ({ + stubResultResolver = { resolveDiscovery: () => { // no body }, @@ -283,8 +283,8 @@ suite('Workspace test adapter', () => { vsIdToRunId: { get: sinon.stub().returns('expectedRunId'), }, - } as unknown) as ITestResultResolver; - const testItem = ({ + } as unknown as ITestResultResolver; + const testItem = { canResolveChildren: false, tags: [], children: { @@ -292,9 +292,9 @@ suite('Workspace test adapter', () => { // empty }, }, - } as unknown) as TestItem; + } as unknown as TestItem; - testController = ({ + testController = { items: { get: () => { log.push('get'); @@ -316,7 +316,7 @@ suite('Workspace test adapter', () => { dispose: () => { // empty }, - } as unknown) as TestController; + } as unknown as TestController; const mockSendTelemetryEvent = ( eventName: EventName, @@ -453,7 +453,7 @@ suite('Workspace test adapter', () => { stubResultResolver, ); - const blankTestItem = ({ + const blankTestItem = { canResolveChildren: false, tags: [], children: { @@ -461,7 +461,7 @@ suite('Workspace test adapter', () => { // empty }, }, - } as unknown) as TestItem; + } as unknown as TestItem; const errorTestItemOptions: testItemUtilities.ErrorTestItemOptions = { id: 'id', label: 'label', @@ -501,7 +501,7 @@ suite('Workspace test adapter', () => { function createMockTestItem(id: string): TestItem { const range = typemoq.Mock.ofType(); - const mockTestItem = ({ + const mockTestItem = { id, canResolveChildren: false, tags: [], @@ -512,7 +512,7 @@ function createMockTestItem(id: string): TestItem { }, range, uri: Uri.file('/foo/bar'), - } as unknown) as TestItem; + } as unknown as TestItem; return mockTestItem; }