From ce2bb21b71a255aa388837b62787cbbca4f791f5 Mon Sep 17 00:00:00 2001 From: Megan Rogge Date: Fri, 6 Feb 2026 14:01:41 -0600 Subject: [PATCH] rm `any` from task files (#293508) task part of #274723 --- eslint.config.js | 11 --- src/vs/workbench/api/common/shared/tasks.ts | 2 +- .../contrib/debug/browser/debugTaskRunner.ts | 2 +- .../tasks/browser/abstractTaskService.ts | 90 ++++++++----------- .../tasks/browser/runAutomaticTasks.ts | 4 +- .../tasks/browser/task.contribution.ts | 2 +- .../tasks/browser/terminalTaskSystem.ts | 18 ++-- .../contrib/tasks/common/jsonSchema_v1.ts | 12 ++- .../contrib/tasks/common/jsonSchema_v2.ts | 14 +-- .../contrib/tasks/common/problemMatcher.ts | 28 +++--- .../contrib/tasks/common/taskConfiguration.ts | 59 ++++++------ .../contrib/tasks/common/taskSystem.ts | 2 +- .../workbench/contrib/tasks/common/tasks.ts | 51 +++++------ 13 files changed, 141 insertions(+), 154 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 4118fd0759a..2a3cec2b0e5 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -564,7 +564,6 @@ export default tseslint.config( 'src/vs/workbench/api/common/extHostWebviewView.ts', 'src/vs/workbench/api/common/extHostWorkspace.ts', 'src/vs/workbench/api/common/extensionHostMain.ts', - 'src/vs/workbench/api/common/shared/tasks.ts', 'src/vs/workbench/api/node/extHostAuthentication.ts', 'src/vs/workbench/api/node/extHostCLIServer.ts', 'src/vs/workbench/api/node/extHostConsoleForwarder.ts', @@ -700,16 +699,6 @@ export default tseslint.config( 'src/vs/workbench/contrib/snippets/browser/commands/configureSnippets.ts', 'src/vs/workbench/contrib/snippets/browser/commands/insertSnippet.ts', 'src/vs/workbench/contrib/snippets/browser/snippetsService.ts', - 'src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts', - 'src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts', - 'src/vs/workbench/contrib/tasks/browser/task.contribution.ts', - 'src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts', - 'src/vs/workbench/contrib/tasks/common/jsonSchema_v1.ts', - 'src/vs/workbench/contrib/tasks/common/jsonSchema_v2.ts', - 'src/vs/workbench/contrib/tasks/common/problemMatcher.ts', - 'src/vs/workbench/contrib/tasks/common/taskConfiguration.ts', - 'src/vs/workbench/contrib/tasks/common/taskSystem.ts', - 'src/vs/workbench/contrib/tasks/common/tasks.ts', 'src/vs/workbench/contrib/testing/common/storedValue.ts', 'src/vs/workbench/contrib/testing/test/browser/testObjectTree.ts', 'src/vs/workbench/contrib/typeHierarchy/browser/typeHierarchy.contribution.ts', diff --git a/src/vs/workbench/api/common/shared/tasks.ts b/src/vs/workbench/api/common/shared/tasks.ts index 0d8faae5d0d..a7e46e70ff8 100644 --- a/src/vs/workbench/api/common/shared/tasks.ts +++ b/src/vs/workbench/api/common/shared/tasks.ts @@ -10,7 +10,7 @@ import { ITaskExecution } from '../../../contrib/tasks/common/tasks.js'; export interface ITaskDefinitionDTO { type: string; - [name: string]: any; + [name: string]: unknown; } export interface ITaskPresentationOptionsDTO { diff --git a/src/vs/workbench/contrib/debug/browser/debugTaskRunner.ts b/src/vs/workbench/contrib/debug/browser/debugTaskRunner.ts index 9374887badd..57d4ad3e8c4 100644 --- a/src/vs/workbench/contrib/debug/browser/debugTaskRunner.ts +++ b/src/vs/workbench/contrib/debug/browser/debugTaskRunner.ts @@ -91,7 +91,7 @@ export class DebugTaskRunner implements IDisposable { return Promise.resolve(TaskRunResult.Failure); } - const taskLabel = typeof taskId === 'string' ? taskId : taskId ? taskId.name : ''; + const taskLabel = typeof taskId === 'string' ? taskId : taskId ? taskId.name as string : ''; const message = errorCount > 1 ? nls.localize('preLaunchTaskErrors', "Errors exist after running preLaunchTask '{0}'.", taskLabel) : errorCount === 1 diff --git a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts index d1de3666a97..c18c3d6ac88 100644 --- a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts +++ b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts @@ -47,7 +47,7 @@ import { ITextFileService } from '../../../services/textfile/common/textfiles.js import { ITerminalGroupService, ITerminalService } from '../../terminal/browser/terminal.js'; import { ITerminalProfileResolverService } from '../../terminal/common/terminal.js'; -import { ConfiguringTask, ContributedTask, CustomTask, ExecutionEngine, InMemoryTask, InstancePolicy, ITaskConfig, ITaskEvent, ITaskIdentifier, ITaskInactiveEvent, ITaskProcessEndedEvent, ITaskSet, JsonSchemaVersion, KeyedTaskIdentifier, RerunAllRunningTasksCommandId, RuntimeType, Task, TASK_RUNNING_STATE, TaskDefinition, TaskEventKind, TaskGroup, TaskRunSource, TaskSettingId, TaskSorter, TaskSourceKind, TasksSchemaProperties, USER_TASKS_GROUP_KEY } from '../common/tasks.js'; +import { CommandString, ConfiguringTask, ContributedTask, CustomTask, ExecutionEngine, InMemoryTask, InstancePolicy, ITaskConfig, ITaskEvent, ITaskIdentifier, ITaskInactiveEvent, ITaskProcessEndedEvent, ITaskSet, JsonSchemaVersion, KeyedTaskIdentifier, RerunAllRunningTasksCommandId, RuntimeType, Task, TASK_RUNNING_STATE, TaskDefinition, TaskEventKind, TaskGroup, TaskRunSource, TaskSettingId, TaskSorter, TaskSourceKind, TasksSchemaProperties, USER_TASKS_GROUP_KEY } from '../common/tasks.js'; import { ChatAgentLocation, ChatModeKind } from '../../chat/common/constants.js'; import { CustomExecutionSupportedContext, ICustomizationProperties, IProblemMatcherRunOptions, ITaskFilter, ITaskProvider, ITaskService, IWorkspaceFolderTaskResult, ProcessExecutionSupportedContext, ServerlessWebContext, ShellExecutionSupportedContext, TaskCommandsRegistered, TaskExecutionSupportedContext, TasksAvailableContext } from '../common/taskService.js'; import { ITaskExecuteResult, ITaskResolver, ITaskSummary, ITaskSystem, ITaskSystemInfo, ITaskTerminateResponse, TaskError, TaskErrors, TaskExecuteKind, Triggers, VerifiedTask } from '../common/taskSystem.js'; @@ -1211,17 +1211,17 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer this.workspaceFolders.forEach(folder => { folderMap[folder.uri.toString()] = folder; }); - const folderToTasksMap: Map = new Map(); - const workspaceToTaskMap: Map = new Map(); + const folderToTasksMap: Map = new Map(); + const workspaceToTaskMap: Map = new Map(); const storedTasks = this._getTasksFromStorage(type); const tasks: (Task | ConfiguringTask)[] = []; this._log(nls.localize('taskService.getSavedTasks', 'Fetching tasks from task storage.'), true); - function addTaskToMap(map: Map, folder: string | undefined, task: any) { + function addTaskToMap(map: Map, folder: string | undefined, task: TaskConfig.ICustomTask | TaskConfig.IConfiguringTask) { if (folder && !map.has(folder)) { map.set(folder, []); } if (folder && (folderMap[folder] || (folder === USER_TASKS_GROUP_KEY)) && task) { - map.get(folder).push(task); + map.get(folder)!.push(task); } } for (const entry of storedTasks.entries()) { @@ -1238,7 +1238,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer const readTasksMap: Map = new Map(); - async function readTasks(that: AbstractTaskService, map: Map, isWorkspaceFile: boolean) { + async function readTasks(that: AbstractTaskService, map: Map, isWorkspaceFile: boolean) { for (const key of map.keys()) { const custom: CustomTask[] = []; const customized: IStringDictionary = Object.create(null); @@ -1478,17 +1478,15 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer if (type === undefined) { return true; } - // eslint-disable-next-line local/code-no-any-casts - const settingValueMap: IStringDictionary = settingValue as any; + const settingValueMap: IStringDictionary = settingValue as IStringDictionary; return !settingValueMap[type]; } private _getTypeForTask(task: Task): string { let type: string; if (CustomTask.is(task)) { - const configProperties: TaskConfig.IConfigurationProperties = task._source.config.element; - // eslint-disable-next-line local/code-no-any-casts - type = (configProperties).type; + const configProperties = task._source.config.element as TaskConfig.ICustomTask; + type = configProperties.type ?? ''; } else { type = task.getDefinition()!.type; } @@ -1513,7 +1511,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer return !task.hasDefinedMatchers && !!task.configurationProperties.problemMatchers && (task.configurationProperties.problemMatchers.length === 0); } if (CustomTask.is(task)) { - const configProperties: TaskConfig.IConfigurationProperties = task._source.config.element; + const configProperties = task._source.config.element as TaskConfig.IConfigurationProperties; return configProperties.problemMatcher === undefined && !task.hasDefinedMatchers; } return false; @@ -1526,8 +1524,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer } let newValue: IStringDictionary; if (current !== false) { - // eslint-disable-next-line local/code-no-any-casts - newValue = current; + newValue = current as IStringDictionary; } else { newValue = Object.create(null); } @@ -1571,9 +1568,8 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer entries.unshift({ type: 'separator', label: nls.localize('TaskService.associate', 'associate') }); let taskType: string; if (CustomTask.is(task)) { - const configProperties: TaskConfig.IConfigurationProperties = task._source.config.element; - // eslint-disable-next-line local/code-no-any-casts - taskType = (configProperties).type; + const configProperties = task._source.config.element as TaskConfig.ICustomTask; + taskType = configProperties.type ?? ''; } else { taskType = task.getDefinition().type; } @@ -1726,8 +1722,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer }; const identifier: TaskConfig.ITaskIdentifier = Object.assign(Object.create(null), task.defines); delete identifier['_key']; - // eslint-disable-next-line local/code-no-any-casts - Object.keys(identifier).forEach(key => (toCustomize)![key] = identifier[key]); + Object.keys(identifier).forEach(key => (toCustomize as unknown as Record)![key] = identifier[key]); if (task.configurationProperties.problemMatchers && task.configurationProperties.problemMatchers.length > 0 && Types.isStringArray(task.configurationProperties.problemMatchers)) { toCustomize.problemMatcher = task.configurationProperties.problemMatchers; } @@ -1773,11 +1768,9 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer const index: number | undefined = CustomTask.is(task) ? task._source.config.index : undefined; if (properties) { for (const property of Object.getOwnPropertyNames(properties)) { - // eslint-disable-next-line local/code-no-any-casts - const value = (properties)[property]; + const value = (properties as Record)[property]; if (value !== undefined && value !== null) { - // eslint-disable-next-line local/code-no-any-casts - (toCustomize)[property] = value; + (toCustomize as unknown as Record)[property] = value; } } } @@ -1791,7 +1784,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer '{', nls.localize('tasksJsonComment', '\t// See https://go.microsoft.com/fwlink/?LinkId=733558 \n\t// for the documentation about the tasks.json format'), ].join('\n') + JSON.stringify(value, null, '\t').substr(1); - const editorConfig = this._configurationService.getValue(); + const editorConfig = this._configurationService.getValue<{ editor: { insertSpaces: boolean; tabSize: number } }>(); if (editorConfig.editor.insertSpaces) { content = content.replace(/(\n)(\t+)/g, (_, s1, s2) => s1 + ' '.repeat(s2.length * editorConfig.editor.tabSize)); } @@ -1824,7 +1817,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer } } - private _writeConfiguration(workspaceFolder: IWorkspaceFolder, key: string, value: any, source?: string): Promise | undefined { + private _writeConfiguration(workspaceFolder: IWorkspaceFolder, key: string, value: unknown, source?: string): Promise | undefined { let target: ConfigurationTarget | undefined = undefined; switch (source) { case TaskSourceKind.User: target = ConfigurationTarget.USER; break; @@ -2321,12 +2314,12 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer resolve(result); } }; - const error = (error: any) => { + const error = (error: unknown) => { try { if (!isCancellationError(error)) { - if (error && Types.isString(error.message)) { - this._log(`Error: ${error.message}\n`); - this._showOutput(error.message); + if (error && Types.isString((error as { message?: string }).message)) { + this._log(`Error: ${(error as { message: string }).message}\n`); + this._showOutput(undefined, undefined, (error as { message: string }).message); } else { this._log('Unknown error received while collecting tasks from providers.'); this._showOutput(); @@ -2665,8 +2658,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer if (!config) { return { config: undefined, hasParseErrors: false }; } - // eslint-disable-next-line local/code-no-any-casts - const parseErrors: string[] = (config as any).$parseErrors; + const parseErrors: string[] = (config as unknown as Record).$parseErrors as string[]; if (parseErrors) { let isAffected = false; for (const parseError of parseErrors) { @@ -2846,8 +2838,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer if (!result) { return { config: undefined, hasParseErrors: false }; } - // eslint-disable-next-line local/code-no-any-casts - const parseErrors: string[] = (result as any).$parseErrors; + const parseErrors: string[] = (result as unknown as Record).$parseErrors as string[]; if (parseErrors) { let isAffected = false; for (const parseError of parseErrors) { @@ -2881,7 +2872,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer }; } - private _handleError(err: any): void { + private _handleError(err: unknown): void { let showOutput = true; if (err instanceof TaskError) { const buildError = err; @@ -2911,7 +2902,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer this._notificationService.error(nls.localize('TaskSystem.unknownError', 'An error has occurred while running a task. See task log for details.')); } if (showOutput) { - this._showOutput(undefined, undefined, err); + this._showOutput(undefined, undefined, Types.isString(err) ? err as string : undefined); } } @@ -3121,7 +3112,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer return this._doRunTaskCommand(); } const type = typeof filter === 'string' ? undefined : filter.type; - const taskName = typeof filter === 'string' ? filter : filter.task; + const taskName = typeof filter === 'string' ? filter : filter.task as string; const grouped = await this._getGroupedTasks({ type }); const identifier = this._getTaskIdentifier(filter); const tasks = grouped.all(); @@ -3140,7 +3131,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer } } } - const exactMatchTask = !taskName ? undefined : tasks.find(t => t.configurationProperties.identifier === taskName || t.getDefinition(true)?.configurationProperties?.identifier === taskName); + const exactMatchTask = !taskName ? undefined : tasks.find(t => t.configurationProperties.identifier === taskName); if (!exactMatchTask) { return this._doRunTaskCommand(tasks, type, taskName); } @@ -3583,8 +3574,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer return Promise.resolve(undefined); } content = pickTemplateResult.content; - // eslint-disable-next-line local/code-no-any-casts - const editorConfig = this._configurationService.getValue() as any; + const editorConfig = this._configurationService.getValue() as { editor: { insertSpaces: boolean; tabSize: number } }; if (editorConfig.editor.insertSpaces) { content = content.replace(/(\n)(\t+)/g, (_, s1, s2) => s1 + ' '.repeat(s2.length * editorConfig.editor.tabSize)); } @@ -3617,14 +3607,12 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer } private _isTaskEntry(value: IQuickPickItem): value is IQuickPickItem & { task: Task } { - // eslint-disable-next-line local/code-no-any-casts - const candidate: IQuickPickItem & { task: Task } = value as any; + const candidate: IQuickPickItem & { task: Task } = value as IQuickPickItem & { task: Task }; return candidate && !!candidate.task; } private _isSettingEntry(value: IQuickPickItem): value is IQuickPickItem & { settingType: string } { - // eslint-disable-next-line local/code-no-any-casts - const candidate: IQuickPickItem & { settingType: string } = value as any; + const candidate: IQuickPickItem & { settingType: string } = value as IQuickPickItem & { settingType: string }; return candidate && !!candidate.settingType; } @@ -3734,8 +3722,8 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer })]); if (!timeout && ((await entries).length === 1) && this._configurationService.getValue(QUICKOPEN_SKIP_CONFIG)) { - const entry: any = (await entries)[0]; - if (entry.task) { + const entry = (await entries)[0] as TaskQuickPickEntryType; + if ((entry as IQuickPickItem & { task: Task }).task) { this._handleSelection(entry); return; } @@ -3752,8 +3740,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer if (cancellationToken.isCancellationRequested) { // canceled when there's only one task const task = (await entries)[0]; - // eslint-disable-next-line local/code-no-any-casts - if ((task).task) { + if ((task as IQuickPickItem & { task: Task }).task) { selection = task; } } @@ -3811,8 +3798,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer if (cancellationToken.isCancellationRequested) { // canceled when there's only one task const task = (await entries)[0]; - // eslint-disable-next-line local/code-no-any-casts - if ((task).task) { + if ((task as IQuickPickItem & { task: Task }).task) { entry = task; } } @@ -3970,13 +3956,13 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer if (task.command.name && !suppressTaskName && !globalConfig.windows?.command && !globalConfig.osx?.command && !globalConfig.linux?.command) { configElement.command = task.command.name; } else if (suppressTaskName) { - configElement.command = task._source.config.element.command; + configElement.command = (task._source.config.element as Record).command as string | CommandString; } if (task.command.args && (!Array.isArray(task.command.args) || (task.command.args.length > 0))) { if (!globalConfig.windows?.args && !globalConfig.osx?.args && !globalConfig.linux?.args) { configElement.args = task.command.args; } else { - configElement.args = task._source.config.element.args; + configElement.args = (task._source.config.element as Record).args as string[] | CommandString[]; } } } @@ -3988,7 +3974,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer configElement.isBackground = task.configurationProperties.isBackground; } if (task.configurationProperties.problemMatchers) { - configElement.problemMatcher = task._source.config.element.problemMatcher; + configElement.problemMatcher = (task._source.config.element as Record).problemMatcher as string[]; } if (task.configurationProperties.group) { configElement.group = task.configurationProperties.group; diff --git a/src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts b/src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts index 080d0432909..2b029d727aa 100644 --- a/src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts +++ b/src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts @@ -144,7 +144,7 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut if (configuredTask._label) { taskNames.push(configuredTask._label); } else { - taskNames.push(configuredTask.configures.task); + taskNames.push(configuredTask.configures.task as string); } const location = this._getTaskSource(configuredTask._source); if (location) { @@ -227,7 +227,7 @@ export class ManageAutomaticTaskRunning extends Action2 { }); } - public async run(accessor: ServicesAccessor): Promise { + public async run(accessor: ServicesAccessor): Promise { const quickInputService = accessor.get(IQuickInputService); const configurationService = accessor.get(IConfigurationService); const allowItem: IQuickPickItem = { label: nls.localize('workbench.action.tasks.allowAutomaticTasks', "Allow Automatic Tasks") }; diff --git a/src/vs/workbench/contrib/tasks/browser/task.contribution.ts b/src/vs/workbench/contrib/tasks/browser/task.contribution.ts index 19a537dd101..4fa7237b82f 100644 --- a/src/vs/workbench/contrib/tasks/browser/task.contribution.ts +++ b/src/vs/workbench/contrib/tasks/browser/task.contribution.ts @@ -597,7 +597,7 @@ registerAction2(class extends Action2 { } }); } - async run(accessor: ServicesAccessor, args: any): Promise { + async run(accessor: ServicesAccessor, args: unknown): Promise { const terminalService = accessor.get(ITerminalService); const taskSystem = accessor.get(ITaskService); const instance = args as ITerminalInstance ?? terminalService.activeInstance; diff --git a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts index 20f2224f54a..4893f05b809 100644 --- a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts +++ b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts @@ -1710,11 +1710,11 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { this._collectMatcherVariables(variables, task.configurationProperties.problemMatchers); if (task.command.runtime === RuntimeType.CustomExecution && (CustomTask.is(task) || ContributedTask.is(task))) { - let definition: any; + let definition: Record | undefined; if (CustomTask.is(task)) { - definition = task._source.config.element; + definition = task._source.config.element as Record; } else { - definition = Objects.deepClone(task.defines); + definition = Objects.deepClone(task.defines) as Record; delete definition._key; delete definition.type; } @@ -1722,14 +1722,14 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { } } - private _collectDefinitionVariables(variables: Set, definition: any): void { + private _collectDefinitionVariables(variables: Set, definition: unknown): void { if (Types.isString(definition)) { this._collectVariables(variables, definition); } else if (Array.isArray(definition)) { - definition.forEach((element: any) => this._collectDefinitionVariables(variables, element)); + definition.forEach((element: unknown) => this._collectDefinitionVariables(variables, element)); } else if (Types.isObject(definition)) { for (const key of Object.keys(definition)) { - this._collectDefinitionVariables(variables, definition[key]); + this._collectDefinitionVariables(variables, (definition as Record)[key]); } } } @@ -1759,7 +1759,7 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { const optionsEnv = options.env; if (optionsEnv) { Object.keys(optionsEnv).forEach((key) => { - const value: any = optionsEnv[key]; + const value = optionsEnv[key]; if (Types.isString(value)) { this._collectVariables(variables, value); } @@ -1912,11 +1912,11 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem { if (options.env) { result.env = Object.create(null); for (const key of Object.keys(options.env)) { - const value: any = options.env[key]; + const value = options.env[key]; if (Types.isString(value)) { result.env![key] = await this._resolveVariable(resolver, value); } else { - result.env![key] = value.toString(); + result.env![key] = String(value); } } } diff --git a/src/vs/workbench/contrib/tasks/common/jsonSchema_v1.ts b/src/vs/workbench/contrib/tasks/common/jsonSchema_v1.ts index 67017b41d2e..4b49951ab7d 100644 --- a/src/vs/workbench/contrib/tasks/common/jsonSchema_v1.ts +++ b/src/vs/workbench/contrib/tasks/common/jsonSchema_v1.ts @@ -74,9 +74,13 @@ Object.getOwnPropertyNames(definitions).forEach(key => { delete definitions[key]; }); -function fixReferences(literal: any) { +function fixReferences(literal: Record | unknown[]) { if (Array.isArray(literal)) { - literal.forEach(fixReferences); + literal.forEach(element => { + if (typeof element === 'object' && element !== null) { + fixReferences(element as Record); + } + }); } else if (typeof literal === 'object') { if (literal['$ref']) { literal['$ref'] = literal['$ref'] + '1'; @@ -84,12 +88,12 @@ function fixReferences(literal: any) { Object.getOwnPropertyNames(literal).forEach(property => { const value = literal[property]; if (Array.isArray(value) || typeof value === 'object') { - fixReferences(value); + fixReferences(value as Record); } }); } } -fixReferences(schema); +fixReferences(schema as unknown as Record); ProblemMatcherRegistry.onReady().then(() => { try { diff --git a/src/vs/workbench/contrib/tasks/common/jsonSchema_v2.ts b/src/vs/workbench/contrib/tasks/common/jsonSchema_v2.ts index d917ab2e032..bdc6eb09448 100644 --- a/src/vs/workbench/contrib/tasks/common/jsonSchema_v2.ts +++ b/src/vs/workbench/contrib/tasks/common/jsonSchema_v2.ts @@ -15,9 +15,13 @@ import * as ConfigurationResolverUtils from '../../../services/configurationReso import { inputsSchema } from '../../../services/configurationResolver/common/configurationResolverSchema.js'; import { getAllCodicons } from '../../../../base/common/codicons.js'; -function fixReferences(literal: any) { +function fixReferences(literal: Record | unknown[]) { if (Array.isArray(literal)) { - literal.forEach(fixReferences); + literal.forEach(element => { + if (typeof element === 'object' && element !== null) { + fixReferences(element as Record); + } + }); } else if (typeof literal === 'object') { if (literal['$ref']) { literal['$ref'] = literal['$ref'] + '2'; @@ -25,7 +29,7 @@ function fixReferences(literal: any) { Object.getOwnPropertyNames(literal).forEach(property => { const value = literal[property]; if (Array.isArray(value) || typeof value === 'object') { - fixReferences(value); + fixReferences(value as Record); } }); } @@ -480,7 +484,7 @@ export function updateTaskDefinitions() { schemaProperties[key] = Objects.deepClone(property); } } - fixReferences(schema); + fixReferences(schema as unknown as Record); taskDefinitions.push(schema); } } @@ -647,7 +651,7 @@ Object.getOwnPropertyNames(definitions).forEach(key => { delete definitions[key]; deprecatedVariableMessage(definitions, newKey); }); -fixReferences(schema); +fixReferences(schema as unknown as Record); export function updateProblemMatchers() { try { diff --git a/src/vs/workbench/contrib/tasks/common/problemMatcher.ts b/src/vs/workbench/contrib/tasks/common/problemMatcher.ts index a758a3e4e86..fad04dd91be 100644 --- a/src/vs/workbench/contrib/tasks/common/problemMatcher.ts +++ b/src/vs/workbench/contrib/tasks/common/problemMatcher.ts @@ -358,8 +358,7 @@ abstract class AbstractLineMatcher implements ILineMatcher { if (trim) { value = Strings.trim(value)!; } - // eslint-disable-next-line local/code-no-any-casts - (data as any)[property] += endOfLine + value; + (data as Record)[property] = data[property]! + endOfLine + value; } } @@ -371,8 +370,7 @@ abstract class AbstractLineMatcher implements ILineMatcher { if (trim) { value = Strings.trim(value)!; } - // eslint-disable-next-line local/code-no-any-casts - (data as any)[property] = value; + (data as Record)[property] = value; } } } @@ -672,7 +670,7 @@ export namespace Config { } export namespace CheckedProblemPattern { - export function is(value: any): value is ICheckedProblemPattern { + export function is(value: unknown): value is ICheckedProblemPattern { const candidate: IProblemPattern = value as IProblemPattern; return candidate && Types.isString(candidate.regexp); } @@ -691,7 +689,7 @@ export namespace Config { } export namespace NamedProblemPattern { - export function is(value: any): value is INamedProblemPattern { + export function is(value: unknown): value is INamedProblemPattern { const candidate: INamedProblemPattern = value as INamedProblemPattern; return candidate && Types.isString(candidate.name); } @@ -706,7 +704,7 @@ export namespace Config { } export namespace NamedCheckedProblemPattern { - export function is(value: any): value is INamedCheckedProblemPattern { + export function is(value: unknown): value is INamedCheckedProblemPattern { const candidate: INamedProblemPattern = value as INamedProblemPattern; return candidate && NamedProblemPattern.is(candidate) && Types.isString(candidate.regexp); } @@ -715,15 +713,15 @@ export namespace Config { export type MultiLineProblemPattern = IProblemPattern[]; export namespace MultiLineProblemPattern { - export function is(value: any): value is MultiLineProblemPattern { - return value && Array.isArray(value); + export function is(value: unknown): value is MultiLineProblemPattern { + return Array.isArray(value); } } export type MultiLineCheckedProblemPattern = ICheckedProblemPattern[]; export namespace MultiLineCheckedProblemPattern { - export function is(value: any): value is MultiLineCheckedProblemPattern { + export function is(value: unknown): value is MultiLineCheckedProblemPattern { if (!MultiLineProblemPattern.is(value)) { return false; } @@ -754,7 +752,7 @@ export namespace Config { } export namespace NamedMultiLineCheckedProblemPattern { - export function is(value: any): value is INamedMultiLineCheckedProblemPattern { + export function is(value: unknown): value is INamedMultiLineCheckedProblemPattern { const candidate = value as INamedMultiLineCheckedProblemPattern; return candidate && Types.isString(candidate.name) && Array.isArray(candidate.patterns) && MultiLineCheckedProblemPattern.is(candidate.patterns); } @@ -937,7 +935,7 @@ export class ProblemPatternParser extends Parser { public parse(value: Config.MultiLineProblemPattern): MultiLineProblemPattern; public parse(value: Config.INamedProblemPattern): INamedProblemPattern; public parse(value: Config.INamedMultiLineCheckedProblemPattern): INamedMultiLineProblemPattern; - public parse(value: Config.IProblemPattern | Config.MultiLineProblemPattern | Config.INamedProblemPattern | Config.INamedMultiLineCheckedProblemPattern): any { + public parse(value: Config.IProblemPattern | Config.MultiLineProblemPattern | Config.INamedProblemPattern | Config.INamedMultiLineCheckedProblemPattern): IProblemPattern | MultiLineProblemPattern | INamedProblemPattern | INamedMultiLineProblemPattern | null { if (Config.NamedMultiLineCheckedProblemPattern.is(value)) { return this.createNamedMultiLineProblemPattern(value); } else if (Config.MultiLineCheckedProblemPattern.is(value)) { @@ -1015,8 +1013,7 @@ export class ProblemPatternParser extends Parser { function copyProperty(result: IProblemPattern, source: Config.IProblemPattern, resultKey: keyof IProblemPattern, sourceKey: keyof Config.IProblemPattern) { const value = source[sourceKey]; if (typeof value === 'number') { - // eslint-disable-next-line local/code-no-any-casts - (result as any)[resultKey] = value; + (result as unknown as Record)[resultKey] = value; } } copyProperty(result, value, 'file', 'file'); @@ -1906,8 +1903,7 @@ class ProblemMatcherRegistryImpl implements IProblemMatcherRegistry { } const matcher = this.get('tsc-watch'); if (matcher) { - // eslint-disable-next-line local/code-no-any-casts - (matcher).tscWatch = true; + (matcher as unknown as Record).tscWatch = true; } resolve(undefined); }); diff --git a/src/vs/workbench/contrib/tasks/common/taskConfiguration.ts b/src/vs/workbench/contrib/tasks/common/taskConfiguration.ts index e87fb5d13dc..8751c633380 100644 --- a/src/vs/workbench/contrib/tasks/common/taskConfiguration.ts +++ b/src/vs/workbench/contrib/tasks/common/taskConfiguration.ts @@ -152,13 +152,13 @@ export interface IRunOptionsConfig { export interface ITaskIdentifier { type?: string; - [name: string]: any; + [name: string]: unknown; } export namespace ITaskIdentifier { - export function is(value: any): value is ITaskIdentifier { - const candidate: ITaskIdentifier = value; - return candidate !== undefined && Types.isString(value.type); + export function is(value: unknown): value is ITaskIdentifier { + const candidate: ITaskIdentifier = value as ITaskIdentifier; + return candidate !== undefined && Types.isString((value as ITaskIdentifier).type); } } @@ -556,7 +556,7 @@ type TaskConfigurationValueWithErrors = { errors?: string[]; }; -const EMPTY_ARRAY: any[] = []; +const EMPTY_ARRAY: never[] = []; Object.freeze(EMPTY_ARRAY); function assignProperty(target: T, source: Partial, key: K) { @@ -588,6 +588,7 @@ interface IMetaData { } +// eslint-disable-next-line @typescript-eslint/no-explicit-any -- IMetaData array holds heterogeneous parser types function _isEmpty(this: void, value: T | undefined, properties: IMetaData[] | undefined, allowEmptyArray: boolean = false): boolean { if (value === undefined || value === null || properties === undefined) { return true; @@ -605,6 +606,7 @@ function _isEmpty(this: void, value: T | undefined, properties: IMetaData(this: void, target: T | undefined, source: T | undefined, properties: IMetaData[]): T | undefined { if (!source || _isEmpty(source, properties)) { return target; @@ -614,19 +616,20 @@ function _assignProperties(this: void, target: T | undefined, source: T | und } for (const meta of properties) { const property = meta.property; - let value: any; + let value: T[keyof T] | undefined; if (meta.type !== undefined) { value = meta.type.assignProperties(target[property], source[property]); } else { value = source[property]; } if (value !== undefined && value !== null) { - target[property] = value; + (target as Record)[property as string] = value; } } return target; } +// eslint-disable-next-line @typescript-eslint/no-explicit-any -- IMetaData array holds heterogeneous parser types function _fillProperties(this: void, target: T | undefined, source: T | undefined, properties: IMetaData[] | undefined, allowEmptyArray: boolean = false): T | undefined { if (!source || _isEmpty(source, properties)) { return target; @@ -636,19 +639,20 @@ function _fillProperties(this: void, target: T | undefined, source: T | undef } for (const meta of properties!) { const property = meta.property; - let value: any; + let value: T[keyof T] | undefined; if (meta.type) { value = meta.type.fillProperties(target[property], source[property]); } else if (target[property] === undefined) { value = source[property]; } if (value !== undefined && value !== null) { - target[property] = value; + (target as Record)[property as string] = value; } } return target; } +// eslint-disable-next-line @typescript-eslint/no-explicit-any -- IMetaData array holds heterogeneous parser types function _fillDefaults(this: void, target: T | undefined, defaults: T | undefined, properties: IMetaData[], context: IParseContext): T | undefined { if (target && Object.isFrozen(target)) { return target; @@ -665,7 +669,7 @@ function _fillDefaults(this: void, target: T | undefined, defaults: T | undef if (target[property] !== undefined) { continue; } - let value: any; + let value: T[keyof T] | undefined; if (meta.type) { value = meta.type.fillDefaults(target[property], context); } else { @@ -673,12 +677,13 @@ function _fillDefaults(this: void, target: T | undefined, defaults: T | undef } if (value !== undefined && value !== null) { - target[property] = value; + (target as Record)[property as string] = value; } } return target; } +// eslint-disable-next-line @typescript-eslint/no-explicit-any -- IMetaData array holds heterogeneous parser types function _freeze(this: void, target: T, properties: IMetaData[]): Readonly | undefined { if (target === undefined || target === null) { return undefined; @@ -772,8 +777,8 @@ namespace ShellConfiguration { const properties: IMetaData[] = [{ property: 'executable' }, { property: 'args' }, { property: 'quoting' }]; - export function is(value: any): value is IShellConfiguration { - const candidate: IShellConfiguration = value; + export function is(value: unknown): value is IShellConfiguration { + const candidate: IShellConfiguration = value as IShellConfiguration; return candidate && (Types.isString(candidate.executable) || Types.isStringArray(candidate.args)); } @@ -1005,6 +1010,7 @@ namespace CommandConfiguration { linux?: IBaseCommandConfigurationShape; } + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- IMetaData array holds heterogeneous parser types const properties: IMetaData[] = [ { property: 'runtime' }, { property: 'name' }, { property: 'options', type: CommandOptions }, { property: 'args' }, { property: 'taskSelector' }, { property: 'suppressTaskName' }, @@ -1196,14 +1202,15 @@ export namespace ProblemMatcherConverter { return result; } - export function fromWithOsConfig(this: void, external: IConfigurationProperties & { [key: string]: any }, context: IParseContext): TaskConfigurationValueWithErrors { + export function fromWithOsConfig(this: void, external: IConfigurationProperties & { [key: string]: unknown }, context: IParseContext): TaskConfigurationValueWithErrors { let result: TaskConfigurationValueWithErrors = {}; - if (external.windows && external.windows.problemMatcher && context.platform === Platform.Windows) { - result = from(external.windows.problemMatcher, context); - } else if (external.osx && external.osx.problemMatcher && context.platform === Platform.Mac) { - result = from(external.osx.problemMatcher, context); - } else if (external.linux && external.linux.problemMatcher && context.platform === Platform.Linux) { - result = from(external.linux.problemMatcher, context); + const osExternal = external as unknown as { windows?: { problemMatcher?: ProblemMatcherConfig.ProblemMatcherType }; osx?: { problemMatcher?: ProblemMatcherConfig.ProblemMatcherType }; linux?: { problemMatcher?: ProblemMatcherConfig.ProblemMatcherType } }; + if (osExternal.windows?.problemMatcher && context.platform === Platform.Windows) { + result = from(osExternal.windows.problemMatcher, context); + } else if (osExternal.osx?.problemMatcher && context.platform === Platform.Mac) { + result = from(osExternal.osx.problemMatcher, context); + } else if (osExternal.linux?.problemMatcher && context.platform === Platform.Linux) { + result = from(osExternal.linux.problemMatcher, context); } else if (external.problemMatcher) { result = from(external.problemMatcher, context); } @@ -1344,6 +1351,7 @@ namespace DependsOrder { namespace ConfigurationProperties { + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- IMetaData array holds heterogeneous parser types const properties: IMetaData[] = [ { property: 'name' }, { property: 'identifier' }, @@ -1358,12 +1366,12 @@ namespace ConfigurationProperties { { property: 'hide' } ]; - export function from(this: void, external: IConfigurationProperties & { [key: string]: any }, context: IParseContext, + export function from(this: void, external: IConfigurationProperties & { [key: string]: unknown }, context: IParseContext, includeCommandOptions: boolean, source: TaskConfigSource, properties?: IJSONSchemaMap): TaskConfigurationValueWithErrors { if (!external) { return {}; } - const result: Tasks.IConfigurationProperties & { [key: string]: any } = {}; + const result: Tasks.IConfigurationProperties & { [key: string]: unknown } = {}; if (properties) { for (const propertyName of Object.keys(properties)) { @@ -1519,7 +1527,7 @@ namespace ConfiguringTask { RunOptions.fromConfiguration(external.runOptions), { hide: external.hide } ); - const configuration = ConfigurationProperties.from(external, context, true, source, typeDeclaration.properties); + const configuration = ConfigurationProperties.from(external as IConfigurationProperties & { [key: string]: unknown }, context, true, source, typeDeclaration.properties); result.addTaskLoadMessages(configuration.errors); if (configuration.value) { result.configurationProperties = Object.assign(result.configurationProperties, configuration.value); @@ -1597,7 +1605,7 @@ namespace CustomTask { identifier: taskName, } ); - const configuration = ConfigurationProperties.from(external, context, false, source); + const configuration = ConfigurationProperties.from(external as IConfigurationProperties & { [key: string]: unknown }, context, false, source); result.addTaskLoadMessages(configuration.errors); if (configuration.value) { result.configurationProperties = Object.assign(result.configurationProperties, configuration.value); @@ -1717,8 +1725,7 @@ export namespace TaskParser { function isCustomTask(value: ICustomTask | IConfiguringTask): value is ICustomTask { const type = value.type; - // eslint-disable-next-line local/code-no-any-casts - const customize = (value as any).customize; + const customize = (value as unknown as Record).customize; return customize === undefined && (type === undefined || type === null || type === Tasks.CUSTOMIZED_TASK_TYPE || type === 'shell' || type === 'process'); } diff --git a/src/vs/workbench/contrib/tasks/common/taskSystem.ts b/src/vs/workbench/contrib/tasks/common/taskSystem.ts index 5b5a12c84f5..ec05fe3438b 100644 --- a/src/vs/workbench/contrib/tasks/common/taskSystem.ts +++ b/src/vs/workbench/contrib/tasks/common/taskSystem.ts @@ -126,7 +126,7 @@ export interface IResolvedVariables { export interface ITaskSystemInfo { platform: Platform; - context: any; + context: unknown; uriProvider: (this: void, path: string) => URI; resolveVariables(workspaceFolder: IWorkspaceFolder, toResolve: IResolveSet, target: ConfigurationTarget): Promise; findExecutable(command: string, cwd?: string, paths?: string[]): Promise; diff --git a/src/vs/workbench/contrib/tasks/common/tasks.ts b/src/vs/workbench/contrib/tasks/common/tasks.ts index 623a81a275f..e44d7c915f9 100644 --- a/src/vs/workbench/contrib/tasks/common/tasks.ts +++ b/src/vs/workbench/contrib/tasks/common/tasks.ts @@ -386,7 +386,7 @@ export namespace TaskGroup { export const Test: TaskGroup = { _id: 'test', isDefault: false }; - export function is(value: any): value is string { + export function is(value: unknown): value is string { return value === Clean._id || value === Build._id || value === Rebuild._id || value === Test._id; } @@ -436,7 +436,7 @@ export interface ITaskSourceConfigElement { workspace?: IWorkspace; file: string; index: number; - element: any; + element: unknown; } export interface ITaskConfig { @@ -471,7 +471,7 @@ export interface IExtensionTaskSource extends IBaseTaskSource { export interface IExtensionTaskSourceTransfer { __workspaceFolder: UriComponents; - __definition: { type: string;[name: string]: any }; + __definition: { type: string;[name: string]: unknown }; } export interface IInMemoryTaskSource extends IBaseTaskSource { @@ -494,7 +494,7 @@ export type TaskSource = IWorkspaceTaskSource | IExtensionTaskSource | IInMemory export type FileBasedTaskSource = IWorkspaceTaskSource | IUserTaskSource | WorkspaceFileTaskSource; export interface ITaskIdentifier { type: string; - [name: string]: any; + [name: string]: unknown; } export interface KeyedTaskIdentifier extends ITaskIdentifier { @@ -664,11 +664,10 @@ export abstract class CommonTask { } public clone(): Task { - // eslint-disable-next-line local/code-no-any-casts - return this.fromObject(Object.assign({}, this)); + return this.fromObject(Object.assign({}, this as unknown as Record)); } - protected abstract fromObject(object: any): Task; + protected abstract fromObject(object: Record): Task; public getWorkspaceFolder(): IWorkspaceFolder | undefined { return undefined; @@ -705,8 +704,7 @@ export abstract class CommonTask { public getTaskExecution(): ITaskExecution { const result: ITaskExecution = { id: this._id, - // eslint-disable-next-line local/code-no-any-casts - task: this + task: this as unknown as Task }; return result; } @@ -806,7 +804,7 @@ export class CustomTask extends CommonTask { } } - public static is(value: any): value is CustomTask { + public static is(value: unknown): value is CustomTask { return value instanceof CustomTask; } @@ -860,8 +858,9 @@ export class CustomTask extends CommonTask { } } - protected fromObject(object: CustomTask): CustomTask { - return new CustomTask(object._id, object._source, object._label, object.type, object.command, object.hasDefinedMatchers, object.runOptions, object.configurationProperties); + protected fromObject(object: Record): CustomTask { + const obj = object as unknown as CustomTask; + return new CustomTask(obj._id, obj._source, obj._label, obj.type, obj.command, obj.hasDefinedMatchers, obj.runOptions, obj.configurationProperties); } } @@ -886,12 +885,12 @@ export class ConfiguringTask extends CommonTask { this.configures = configures; } - public static is(value: any): value is ConfiguringTask { + public static is(value: unknown): value is ConfiguringTask { return value instanceof ConfiguringTask; } - protected fromObject(object: any): Task { - return object; + protected fromObject(object: Record): Task { + return object as unknown as Task; } public override getDefinition(): KeyedTaskIdentifier { @@ -980,7 +979,7 @@ export class ContributedTask extends CommonTask { return this.defines; } - public static is(value: any): value is ContributedTask { + public static is(value: unknown): value is ContributedTask { return value instanceof ContributedTask; } @@ -1019,8 +1018,9 @@ export class ContributedTask extends CommonTask { return 'extension'; } - protected fromObject(object: ContributedTask): ContributedTask { - return new ContributedTask(object._id, object._source, object._label, object.type, object.defines, object.command, object.hasDefinedMatchers, object.runOptions, object.configurationProperties); + protected fromObject(object: Record): ContributedTask { + const obj = object as unknown as ContributedTask; + return new ContributedTask(obj._id, obj._source, obj._label, obj.type, obj.defines, obj.command, obj.hasDefinedMatchers, obj.runOptions, obj.configurationProperties); } } @@ -1044,7 +1044,7 @@ export class InMemoryTask extends CommonTask { return new InMemoryTask(this._id, this._source, this._label, this.type, this.runOptions, this.configurationProperties); } - public static is(value: any): value is InMemoryTask { + public static is(value: unknown): value is InMemoryTask { return value instanceof InMemoryTask; } @@ -1060,8 +1060,9 @@ export class InMemoryTask extends CommonTask { return undefined; } - protected fromObject(object: InMemoryTask): InMemoryTask { - return new InMemoryTask(object._id, object._source, object._label, object.type, object.runOptions, object.configurationProperties); + protected fromObject(object: Record): InMemoryTask { + const obj = object as unknown as InMemoryTask; + return new InMemoryTask(obj._id, obj._source, obj._label, obj.type, obj.runOptions, obj.configurationProperties); } } @@ -1331,13 +1332,13 @@ export namespace TaskEvent { } export namespace KeyedTaskIdentifier { - function sortedStringify(literal: any): string { + function sortedStringify(literal: Record): string { const keys = Object.keys(literal).sort(); let result: string = ''; for (const key of keys) { let stringified = literal[key]; if (stringified instanceof Object) { - stringified = sortedStringify(stringified); + stringified = sortedStringify(stringified as Record); } else if (typeof stringified === 'string') { stringified = stringified.replace(/,/g, ',,'); } @@ -1347,7 +1348,7 @@ export namespace KeyedTaskIdentifier { } export function create(value: ITaskIdentifier): KeyedTaskIdentifier { const resultKey = sortedStringify(value); - const result = { _key: resultKey, type: value.taskType }; + const result = { _key: resultKey, type: value.taskType as string }; Object.assign(result, value); return result; } @@ -1390,7 +1391,7 @@ export namespace TaskDefinition { return KeyedTaskIdentifier.create(copy); } - const literal: { type: string;[name: string]: any } = Object.create(null); + const literal: { type: string;[name: string]: unknown } = Object.create(null); literal.type = definition.taskType; const required: Set = new Set(); definition.required.forEach(element => required.add(element));