diff --git a/packages/bulk-edit/src/browser/bulk-edit-tree/bulk-edit-node-selection.ts b/packages/bulk-edit/src/browser/bulk-edit-tree/bulk-edit-node-selection.ts index 9e139b644bcc6..179018ceacd42 100644 --- a/packages/bulk-edit/src/browser/bulk-edit-tree/bulk-edit-node-selection.ts +++ b/packages/bulk-edit/src/browser/bulk-edit-tree/bulk-edit-node-selection.ts @@ -22,8 +22,8 @@ export interface BulkEditNodeSelection { bulkEdit: ResourceFileEdit | ResourceTextEdit; } export namespace BulkEditNodeSelection { - export function is(arg: Object | undefined): arg is BulkEditNodeSelection { - return typeof arg === 'object' && ('bulkEdit' in arg); + export function is(arg: unknown): arg is BulkEditNodeSelection { + return !!arg && typeof arg === 'object' && ('bulkEdit' in arg); } export class CommandHandler extends SelectionCommandHandler { diff --git a/packages/bulk-edit/src/browser/bulk-edit-tree/bulk-edit-tree.ts b/packages/bulk-edit/src/browser/bulk-edit-tree/bulk-edit-tree.ts index 26dcdeb516645..b224da25a69d0 100644 --- a/packages/bulk-edit/src/browser/bulk-edit-tree/bulk-edit-tree.ts +++ b/packages/bulk-edit/src/browser/bulk-edit-tree/bulk-edit-tree.ts @@ -108,7 +108,7 @@ export interface BulkEditInfoNode extends UriSelection, SelectableTreeNode, Expa fileContents?: string; } export namespace BulkEditInfoNode { - export function is(node: Object | undefined): node is BulkEditInfoNode { + export function is(node: unknown): node is BulkEditInfoNode { return ExpandableTreeNode.is(node) && UriSelection.is(node) && 'fileContents' in node; } } diff --git a/packages/core/src/browser/common-frontend-contribution.ts b/packages/core/src/browser/common-frontend-contribution.ts index 9aac0b62fabaa..1cf96d0e8a1e5 100644 --- a/packages/core/src/browser/common-frontend-contribution.ts +++ b/packages/core/src/browser/common-frontend-contribution.ts @@ -1234,13 +1234,11 @@ export class CommonFrontendContribution implements FrontendApplicationContributi { placeholder: nls.localizeByDefault('Select Color Theme (Up/Down Keys to Preview)'), activeItem: items.find((item: QuickPickItem) => item.id === resetTo), - // eslint-disable-next-line @typescript-eslint/no-explicit-any - onDidChangeSelection: (quickPick: any, selectedItems: Array) => { + onDidChangeSelection: (quickPick: QuickPick, selectedItems: Array) => { resetTo = undefined; previewTheme(selectedItems[0].id!); }, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - onDidChangeActive: (quickPick: any, activeItems: Array) => { + onDidChangeActive: (quickPick: QuickPick, activeItems: Array) => { previewTheme(activeItems[0].id!); }, onDidHide: () => { diff --git a/packages/core/src/browser/label-provider.ts b/packages/core/src/browser/label-provider.ts index b862149f26f47..565246692fc11 100644 --- a/packages/core/src/browser/label-provider.ts +++ b/packages/core/src/browser/label-provider.ts @@ -93,9 +93,8 @@ export interface URIIconReference { uri?: URI } export namespace URIIconReference { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function is(element: any | undefined): element is URIIconReference { - return !!element && typeof element === 'object' && 'kind' in element && element['kind'] === 'uriIconReference'; + export function is(element: unknown): element is URIIconReference { + return !!element && typeof element === 'object' && 'kind' in element && (element as URIIconReference).kind === 'uriIconReference'; } export function create(id: URIIconReference['id'], uri?: URI): URIIconReference { return { kind: 'uriIconReference', id, uri }; diff --git a/packages/core/src/browser/menu/browser-context-menu-renderer.ts b/packages/core/src/browser/menu/browser-context-menu-renderer.ts index 469c08bc69408..ce155e75f9c88 100644 --- a/packages/core/src/browser/menu/browser-context-menu-renderer.ts +++ b/packages/core/src/browser/menu/browser-context-menu-renderer.ts @@ -14,8 +14,6 @@ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 // ***************************************************************************** -/* eslint-disable @typescript-eslint/no-explicit-any */ - import { inject, injectable } from 'inversify'; import { Menu } from '../widgets'; import { ContextMenuAccess, ContextMenuRenderer, coordinateFromAnchor, RenderContextMenuOptions } from '../context-menu-renderer'; diff --git a/packages/core/src/browser/navigatable-types.ts b/packages/core/src/browser/navigatable-types.ts index 370868afc73fb..a52f39491d139 100644 --- a/packages/core/src/browser/navigatable-types.ts +++ b/packages/core/src/browser/navigatable-types.ts @@ -33,14 +33,14 @@ export interface Navigatable { } export namespace Navigatable { - export function is(arg: Object | undefined): arg is Navigatable { - return !!arg && 'getResourceUri' in arg && 'createMoveToUri' in arg; + export function is(arg: unknown): arg is Navigatable { + return !!arg && typeof arg === 'object' && 'getResourceUri' in arg && 'createMoveToUri' in arg; } } export type NavigatableWidget = BaseWidget & Navigatable; export namespace NavigatableWidget { - export function is(arg: Object | undefined): arg is NavigatableWidget { + export function is(arg: unknown): arg is NavigatableWidget { return arg instanceof BaseWidget && Navigatable.is(arg); } export function* getAffected( @@ -76,8 +76,7 @@ export interface NavigatableWidgetOptions { counter?: number, } export namespace NavigatableWidgetOptions { - export function is(arg: Object | undefined): arg is NavigatableWidgetOptions { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return !!arg && 'kind' in arg && (arg as any).kind === 'navigatable'; + export function is(arg: unknown): arg is NavigatableWidgetOptions { + return !!arg && typeof arg === 'object' && 'kind' in arg && (arg as NavigatableWidgetOptions).kind === 'navigatable'; } } diff --git a/packages/core/src/browser/preferences/injectable-preference-proxy.ts b/packages/core/src/browser/preferences/injectable-preference-proxy.ts index b57ce36feca95..b5addbf63c613 100644 --- a/packages/core/src/browser/preferences/injectable-preference-proxy.ts +++ b/packages/core/src/browser/preferences/injectable-preference-proxy.ts @@ -108,7 +108,7 @@ export class InjectablePreferenceProxy> impl if (this.schema && (this.isFlat || !property.includes('.')) && this.schema.properties[preferenceName]) { const { overrideIdentifier } = this; const toGet = overrideIdentifier ? this.preferences.overridePreferenceName({ overrideIdentifier, preferenceName }) : preferenceName; - return this.getValue(toGet as keyof T & string, undefined as any); // eslint-disable-line @typescript-eslint/no-explicit-any + return this.getValue(toGet as keyof T & string, undefined!); } switch (property) { case 'onPreferenceChanged': diff --git a/packages/core/src/browser/shell/application-shell.ts b/packages/core/src/browser/shell/application-shell.ts index 7d3c4e0a66445..51b9ffd830576 100644 --- a/packages/core/src/browser/shell/application-shell.ts +++ b/packages/core/src/browser/shell/application-shell.ts @@ -2059,8 +2059,8 @@ export namespace ApplicationShell { } export namespace TrackableWidgetProvider { - export function is(widget: object | undefined): widget is TrackableWidgetProvider { - return !!widget && 'getTrackableWidgets' in widget; + export function is(widget: unknown): widget is TrackableWidgetProvider { + return !!widget && typeof widget === 'object' && 'getTrackableWidgets' in widget; } } diff --git a/packages/core/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar-types.ts b/packages/core/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar-types.ts index 3a4ebc623d87b..acf15dd917bbc 100644 --- a/packages/core/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar-types.ts +++ b/packages/core/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar-types.ts @@ -171,9 +171,8 @@ export namespace TabBarToolbarItem { return (left.priority || 0) - (right.priority || 0); }; - export function is(arg: Object | undefined): arg is TabBarToolbarItem { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return !!arg && 'command' in arg && typeof (arg as any).command === 'string'; + export function is(arg: unknown): arg is TabBarToolbarItem { + return !!arg && typeof arg === 'object' && 'command' in arg && typeof (arg as TabBarToolbarItem).command === 'string'; } } diff --git a/packages/core/src/browser/shell/tab-bars.ts b/packages/core/src/browser/shell/tab-bars.ts index 0197bab4310d6..fc24836bd4db6 100644 --- a/packages/core/src/browser/shell/tab-bars.ts +++ b/packages/core/src/browser/shell/tab-bars.ts @@ -276,7 +276,6 @@ export class TabBarRenderer extends TabBar.Renderer { */ protected getDecorations(title: Title): WidgetDecoration.Data[] { if (this.tabBar && this.decoratorService) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any const owner: { resetTabBarDecorations?: () => void; } & Widget = title.owner; if (!owner.resetTabBarDecorations) { owner.resetTabBarDecorations = () => this.decorations.delete(title); diff --git a/packages/core/src/browser/shell/view-contribution.ts b/packages/core/src/browser/shell/view-contribution.ts index c5fd7ec765e41..387bfc5bbc789 100644 --- a/packages/core/src/browser/shell/view-contribution.ts +++ b/packages/core/src/browser/shell/view-contribution.ts @@ -41,8 +41,7 @@ export interface ViewContributionOptions { toggleKeybinding?: string; } -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export function bindViewContribution>(bind: interfaces.Bind, identifier: interfaces.Newable): interfaces.BindingWhenOnSyntax { +export function bindViewContribution>(bind: interfaces.Bind, identifier: interfaces.Newable): interfaces.BindingWhenOnSyntax { const syntax = bind(identifier).toSelf().inSingletonScope(); bind(CommandContribution).toService(identifier); bind(KeybindingContribution).toService(identifier); diff --git a/packages/core/src/browser/tree/tree-expansion.ts b/packages/core/src/browser/tree/tree-expansion.ts index b4ae7abdfc00b..9a5bf8088cebd 100644 --- a/packages/core/src/browser/tree/tree-expansion.ts +++ b/packages/core/src/browser/tree/tree-expansion.ts @@ -69,11 +69,11 @@ export namespace ExpandableTreeNode { return !!node && CompositeTreeNode.is(node) && 'expanded' in node; } - export function isExpanded(node: Object | undefined): node is ExpandableTreeNode { + export function isExpanded(node: unknown): node is ExpandableTreeNode { return ExpandableTreeNode.is(node) && node.expanded; } - export function isCollapsed(node: Object | undefined): node is ExpandableTreeNode { + export function isCollapsed(node: unknown): node is ExpandableTreeNode { return ExpandableTreeNode.is(node) && !node.expanded; } } diff --git a/packages/core/src/browser/tree/tree-selection-state.ts b/packages/core/src/browser/tree/tree-selection-state.ts index 57015e4bde9af..431e414db4099 100644 --- a/packages/core/src/browser/tree/tree-selection-state.ts +++ b/packages/core/src/browser/tree/tree-selection-state.ts @@ -36,7 +36,7 @@ export namespace FocusableTreeSelection { /** * `true` if the argument is a focusable tree selection. Otherwise, `false`. */ - export function is(arg: object | undefined): arg is FocusableTreeSelection { + export function is(arg: unknown): arg is FocusableTreeSelection { return TreeSelection.is(arg) && 'focus' in arg; } diff --git a/packages/core/src/browser/tree/tree-selection.ts b/packages/core/src/browser/tree/tree-selection.ts index ccc971b9d0cce..d358008b91ba7 100644 --- a/packages/core/src/browser/tree/tree-selection.ts +++ b/packages/core/src/browser/tree/tree-selection.ts @@ -86,8 +86,8 @@ export namespace TreeSelection { RANGE } - export function is(arg: Object | undefined): arg is TreeSelection { - return !!arg && 'node' in arg; + export function is(arg: unknown): arg is TreeSelection { + return !!arg && typeof arg === 'object' && 'node' in arg; } export function isRange(arg: TreeSelection | SelectionType | undefined): boolean { @@ -129,11 +129,11 @@ export interface SelectableTreeNode extends TreeNode { export namespace SelectableTreeNode { - export function is(node: TreeNode | undefined): node is SelectableTreeNode { - return !!node && 'selected' in node; + export function is(node: unknown): node is SelectableTreeNode { + return TreeNode.is(node) && 'selected' in node; } - export function isSelected(node: TreeNode | undefined): node is SelectableTreeNode { + export function isSelected(node: unknown): node is SelectableTreeNode { return is(node) && node.selected; } diff --git a/packages/core/src/browser/tree/tree-widget-selection.ts b/packages/core/src/browser/tree/tree-widget-selection.ts index aaaec788acb50..7d40b10672c5a 100644 --- a/packages/core/src/browser/tree/tree-widget-selection.ts +++ b/packages/core/src/browser/tree/tree-widget-selection.ts @@ -21,15 +21,14 @@ export type TreeWidgetSelection = ReadonlyArray> & source: TreeWidget }; export namespace TreeWidgetSelection { - export function isSource(selection: Object | undefined, source: TreeWidget): selection is TreeWidgetSelection { + export function isSource(selection: unknown, source: TreeWidget): selection is TreeWidgetSelection { return getSource(selection) === source; } - export function getSource(selection: Object | undefined): TreeWidget | undefined { + export function getSource(selection: unknown): TreeWidget | undefined { return is(selection) ? selection.source : undefined; } - export function is(selection: Object | undefined): selection is TreeWidgetSelection { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return Array.isArray(selection) && ('source' in selection) && selection['source'] instanceof TreeWidget; + export function is(selection: unknown): selection is TreeWidgetSelection { + return Array.isArray(selection) && ('source' in selection) && (selection as TreeWidgetSelection).source instanceof TreeWidget; } export function create(source: TreeWidget): TreeWidgetSelection { diff --git a/packages/core/src/browser/tree/tree.ts b/packages/core/src/browser/tree/tree.ts index a719554f1f601..8a65875b61499 100644 --- a/packages/core/src/browser/tree/tree.ts +++ b/packages/core/src/browser/tree/tree.ts @@ -123,7 +123,7 @@ export interface TreeNode { } export namespace TreeNode { - export function is(node: Object | undefined): node is TreeNode { + export function is(node: unknown): node is TreeNode { return !!node && typeof node === 'object' && 'id' in node && 'parent' in node; } diff --git a/packages/core/src/browser/view-container.ts b/packages/core/src/browser/view-container.ts index e97908463336c..56e267d4c2229 100644 --- a/packages/core/src/browser/view-container.ts +++ b/packages/core/src/browser/view-container.ts @@ -63,13 +63,13 @@ export interface BadgeWidget { } export namespace DescriptionWidget { - export function is(arg: Object | undefined): arg is DescriptionWidget { + export function is(arg: unknown): arg is DescriptionWidget { return !!arg && typeof arg === 'object' && 'onDidChangeDescription' in arg; } } export namespace BadgeWidget { - export function is(arg: Object | undefined): arg is BadgeWidget { + export function is(arg: unknown): arg is BadgeWidget { return !!arg && typeof arg === 'object' && 'onDidChangeBadge' in arg; } } diff --git a/packages/core/src/browser/widgets/widget.ts b/packages/core/src/browser/widgets/widget.ts index 863e68b4d6d26..5274d0f2386a6 100644 --- a/packages/core/src/browser/widgets/widget.ts +++ b/packages/core/src/browser/widgets/widget.ts @@ -246,9 +246,8 @@ export interface EventListenerObject { handleEvent(evt: HTMLElementEventMap[K]): void; } export namespace EventListenerObject { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function is(listener: any | undefined): listener is EventListenerObject { - return !!listener && 'handleEvent' in listener; + export function is(listener: unknown): listener is EventListenerObject { + return !!listener && typeof listener === 'object' && 'handleEvent' in listener; } } export type EventListenerOrEventListenerObject = EventListener | EventListenerObject; diff --git a/packages/core/src/common/preferences/preference-schema.ts b/packages/core/src/common/preferences/preference-schema.ts index 140dc3c228669..23449e9760007 100644 --- a/packages/core/src/common/preferences/preference-schema.ts +++ b/packages/core/src/common/preferences/preference-schema.ts @@ -27,8 +27,8 @@ export interface PreferenceSchema { properties: PreferenceSchemaProperties } export namespace PreferenceSchema { - export function is(obj: Object | undefined): obj is PreferenceSchema { - return !!obj && ('properties' in obj) && PreferenceSchemaProperties.is((obj)['properties']); + export function is(obj: unknown): obj is PreferenceSchema { + return !!obj && typeof obj === 'object' && ('properties' in obj) && PreferenceSchemaProperties.is((obj as PreferenceSchema).properties); } export function getDefaultScope(schema: PreferenceSchema): PreferenceScope { let defaultScope: PreferenceScope = PreferenceScope.Workspace; diff --git a/packages/core/src/common/selection.ts b/packages/core/src/common/selection.ts index 40345d3ca0c66..62deee5e06a5e 100644 --- a/packages/core/src/common/selection.ts +++ b/packages/core/src/common/selection.ts @@ -22,12 +22,11 @@ export interface UriSelection { export namespace UriSelection { - export function is(arg: Object | undefined): arg is UriSelection { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return typeof arg === 'object' && ('uri' in arg) && (arg)['uri'] instanceof URI; + export function is(arg: unknown): arg is UriSelection { + return !!arg && typeof arg === 'object' && ('uri' in arg) && (arg as UriSelection).uri instanceof URI; } - export function getUri(selection: Object | undefined): URI | undefined { + export function getUri(selection: unknown): URI | undefined { if (is(selection)) { return selection.uri; } @@ -37,7 +36,7 @@ export namespace UriSelection { return undefined; } - export function getUris(selection: Object | undefined): URI[] { + export function getUris(selection: unknown): URI[] { if (is(selection)) { return [selection.uri]; } diff --git a/packages/debug/src/common/debug-configuration.ts b/packages/debug/src/common/debug-configuration.ts index 262c75b810438..6abd0a8a725d6 100644 --- a/packages/debug/src/common/debug-configuration.ts +++ b/packages/debug/src/common/debug-configuration.ts @@ -56,7 +56,7 @@ export interface DebugConfiguration { * The data is sent as the 'restart' attribute of the 'terminated' event. * The client should leave the data intact. */ - __restart?: any; + __restart?: boolean; /** default: neverOpen */ openDebug?: 'neverOpen' | 'openOnSessionStart' | 'openOnFirstSessionStart' | 'openOnDebugBreak'; @@ -71,7 +71,7 @@ export interface DebugConfiguration { postDebugTask?: string | TaskIdentifier; } export namespace DebugConfiguration { - export function is(arg: DebugConfiguration | any): arg is DebugConfiguration { + export function is(arg: unknown): arg is DebugConfiguration { return !!arg && typeof arg === 'object' && 'type' in arg && 'name' in arg && 'request' in arg; } } diff --git a/packages/debug/src/node/debug-adapter-factory.ts b/packages/debug/src/node/debug-adapter-factory.ts index cf0792d1233c2..dd0b0b9026e3f 100644 --- a/packages/debug/src/node/debug-adapter-factory.ts +++ b/packages/debug/src/node/debug-adapter-factory.ts @@ -66,9 +66,8 @@ export class LaunchBasedDebugAdapterFactory implements DebugAdapterFactory { } private childProcess(executable: DebugAdapterExecutable): RawProcess { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const isForkOptions = (forkOptions: RawForkOptions | any): forkOptions is RawForkOptions => - !!forkOptions && !!forkOptions.modulePath; + const isForkOptions = (forkOptions: unknown): forkOptions is RawForkOptions => + !!forkOptions && typeof forkOptions === 'object' && 'modulePath' in forkOptions; const processOptions: RawProcessOptions | RawForkOptions = { ...executable }; const options: { stdio: (string | number)[], env?: object, execArgv?: string[] } = { stdio: ['pipe', 'pipe', 2] }; diff --git a/packages/editor/src/browser/editor.ts b/packages/editor/src/browser/editor.ts index a5f95136fab2b..12a1cf85c21e2 100644 --- a/packages/editor/src/browser/editor.ts +++ b/packages/editor/src/browser/editor.ts @@ -331,9 +331,8 @@ export interface ReplaceOperation { } export namespace TextEditorSelection { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function is(e: any): e is TextEditorSelection { - return e && e['uri'] instanceof URI; + export function is(e: unknown): e is TextEditorSelection { + return !!e && typeof e === 'object' && (e as TextEditorSelection).uri instanceof URI; } } diff --git a/packages/filesystem/src/browser/file-selection.ts b/packages/filesystem/src/browser/file-selection.ts index f08b59981bb79..81aefa5942992 100644 --- a/packages/filesystem/src/browser/file-selection.ts +++ b/packages/filesystem/src/browser/file-selection.ts @@ -22,8 +22,8 @@ export interface FileSelection { fileStat: FileStat } export namespace FileSelection { - export function is(arg: Object | undefined): arg is FileSelection { - return typeof arg === 'object' && ('fileStat' in arg) && FileStat.is(arg['fileStat']); + export function is(arg: unknown): arg is FileSelection { + return !!arg && typeof arg === 'object' && ('fileStat' in arg) && FileStat.is((arg as FileSelection).fileStat); } export class CommandHandler extends SelectionCommandHandler { diff --git a/packages/filesystem/src/browser/file-tree/file-tree.ts b/packages/filesystem/src/browser/file-tree/file-tree.ts index e347a46bb7c04..733ec2766e9c4 100644 --- a/packages/filesystem/src/browser/file-tree/file-tree.ts +++ b/packages/filesystem/src/browser/file-tree/file-tree.ts @@ -101,8 +101,8 @@ export class FileTree extends TreeImpl { export interface FileStatNode extends SelectableTreeNode, Mutable, FileSelection { } export namespace FileStatNode { - export function is(node: object | undefined): node is FileStatNode { - return !!node && 'fileStat' in node; + export function is(node: unknown): node is FileStatNode { + return !!node && typeof node === 'object' && 'fileStat' in node; } export function getUri(node: TreeNode | undefined): string | undefined { @@ -119,21 +119,21 @@ export type FileStatNodeData = Omit & { fileStat?: FileStat }; export namespace FileStatNodeData { - export function is(node: object | undefined): node is FileStatNodeData { - return !!node && 'uri' in node && ('fileStat' in node || 'stat' in node); + export function is(node: unknown): node is FileStatNodeData { + return !!node && typeof node === 'object' && 'uri' in node && ('fileStat' in node || 'stat' in node); } } export type FileNode = FileStatNode; export namespace FileNode { - export function is(node: Object | undefined): node is FileNode { + export function is(node: unknown): node is FileNode { return FileStatNode.is(node) && !node.fileStat.isDirectory; } } export type DirNode = FileStatNode & ExpandableTreeNode; export namespace DirNode { - export function is(node: Object | undefined): node is DirNode { + export function is(node: unknown): node is DirNode { return FileStatNode.is(node) && node.fileStat.isDirectory; } diff --git a/packages/filesystem/src/common/download/file-download-data.ts b/packages/filesystem/src/common/download/file-download-data.ts index fab1fb708101b..048e8da47bce9 100644 --- a/packages/filesystem/src/common/download/file-download-data.ts +++ b/packages/filesystem/src/common/download/file-download-data.ts @@ -19,7 +19,7 @@ export interface FileDownloadData { } export namespace FileDownloadData { - export function is(arg: Object | undefined): arg is FileDownloadData { - return !!arg && 'uris' in arg; + export function is(arg: unknown): arg is FileDownloadData { + return !!arg && typeof arg === 'object' && 'uris' in arg; } } diff --git a/packages/filesystem/src/common/files.ts b/packages/filesystem/src/common/files.ts index dde1eac4ecb1d..2dfed8108bb9c 100644 --- a/packages/filesystem/src/common/files.ts +++ b/packages/filesystem/src/common/files.ts @@ -200,11 +200,10 @@ export interface BaseStat { etag?: string; } export namespace BaseStat { - export function is(arg: Object | undefined): arg is BaseStat { + export function is(arg: unknown): arg is BaseStat { return !!arg && typeof arg === 'object' - // eslint-disable-next-line @typescript-eslint/no-explicit-any - && ('resource' in arg && arg['resource'] instanceof URI) - && ('name' in arg && typeof arg['name'] === 'string'); + && ('resource' in arg && (arg as BaseStat).resource instanceof URI) + && ('name' in arg && typeof (arg as BaseStat).name === 'string'); } } @@ -241,11 +240,12 @@ export interface FileStat extends BaseStat { children?: FileStat[]; } export namespace FileStat { - export function is(arg: Object | undefined): arg is FileStat { - return BaseStat.is(arg) && - ('isFile' in arg && typeof arg['isFile'] === 'boolean') && - ('isDirectory' in arg && typeof arg['isDirectory'] === 'boolean') && - ('isSymbolicLink' in arg && typeof arg['isSymbolicLink'] === 'boolean'); + export function is(arg: unknown): arg is FileStat { + const fileStat = arg as FileStat; + return BaseStat.is(fileStat) && + ('isFile' in fileStat && typeof fileStat.isFile === 'boolean') && + ('isDirectory' in fileStat && typeof fileStat.isDirectory === 'boolean') && + ('isSymbolicLink' in fileStat && typeof fileStat.isSymbolicLink === 'boolean'); } export function asFileType(stat: FileStat): FileType { let res = 0; diff --git a/packages/git/src/browser/diff/git-diff-contribution.ts b/packages/git/src/browser/diff/git-diff-contribution.ts index ccaff9aba8f14..82b4de5d044e3 100644 --- a/packages/git/src/browser/diff/git-diff-contribution.ts +++ b/packages/git/src/browser/diff/git-diff-contribution.ts @@ -178,14 +178,12 @@ export class GitDiffContribution extends AbstractViewContribution }); const viewModeEmitter = new Emitter(); - /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ - const extractDiffWidget = (widget: any) => { + const extractDiffWidget = (widget: unknown) => { if (widget instanceof GitDiffWidget) { return widget; } }; - /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ - const extractCommitDetailWidget = (widget: any) => { + const extractCommitDetailWidget = (widget: unknown) => { const ref = widget ? widget : this.editorManager.currentEditor; if (ref instanceof GitCommitDetailWidget) { return ref; diff --git a/packages/git/src/browser/diff/git-diff-widget.tsx b/packages/git/src/browser/diff/git-diff-widget.tsx index edd935eea1b8e..ad06f15b8fa85 100644 --- a/packages/git/src/browser/diff/git-diff-widget.tsx +++ b/packages/git/src/browser/diff/git-diff-widget.tsx @@ -28,8 +28,6 @@ import { ScmTreeWidget } from '@theia/scm/lib/browser/scm-tree-widget'; import { ScmPreferences } from '@theia/scm/lib/browser/scm-preferences'; import { nls } from '@theia/core'; -/* eslint-disable @typescript-eslint/no-explicit-any */ - export const GIT_DIFF = 'git-diff'; @injectable() export class GitDiffWidget extends BaseWidget implements StatefulWidget { @@ -135,14 +133,15 @@ export class GitDiffWidget extends BaseWidget implements StatefulWidget { this.resourceWidget.goToNextChange(); } - storeState(): any { - const state: object = { + storeState(): object { + const state = { commitState: this.diffHeaderWidget.storeState(), changesTreeState: this.resourceWidget.storeState(), }; return state; } + // eslint-disable-next-line @typescript-eslint/no-explicit-any restoreState(oldState: any): void { const { commitState, changesTreeState } = oldState; this.diffHeaderWidget.restoreState(commitState); diff --git a/packages/git/src/common/git-model.ts b/packages/git/src/common/git-model.ts index ff87dfe7e41a9..64b8bd3cd2cca 100644 --- a/packages/git/src/common/git-model.ts +++ b/packages/git/src/common/git-model.ts @@ -212,8 +212,8 @@ export namespace Repository { } return repository === repository2; } - export function is(repository: Object | undefined): repository is Repository { - return !!repository && 'localUri' in repository; + export function is(repository: unknown): repository is Repository { + return !!repository && typeof repository === 'object' && 'localUri' in repository; } export function relativePath(repository: Repository | URI, uri: URI | string): Path | undefined { const repositoryUri = new URI(Repository.is(repository) ? repository.localUri : String(repository)); diff --git a/packages/git/src/common/git-watcher.ts b/packages/git/src/common/git-watcher.ts index c381ea368fbb8..a078e376f3cb3 100644 --- a/packages/git/src/common/git-watcher.ts +++ b/packages/git/src/common/git-watcher.ts @@ -47,9 +47,8 @@ export namespace GitStatusChangeEvent { * `true` if the argument is a `GitStatusEvent`, otherwise `false`. * @param event the argument to check whether it is a Git status change event or not. */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function is(event: any | undefined): event is GitStatusChangeEvent { - return !!event && ('source' in event) && ('status' in event); + export function is(event: unknown): event is GitStatusChangeEvent { + return !!event && typeof event === 'object' && ('source' in event) && ('status' in event); } } diff --git a/packages/git/src/common/git.ts b/packages/git/src/common/git.ts index 6cdd540de2269..9ed52916f2b35 100644 --- a/packages/git/src/common/git.ts +++ b/packages/git/src/common/git.ts @@ -846,56 +846,50 @@ export interface Git extends Disposable { } /** - * Contains a set of utility functions for [Git](#Git). + * Contains a set of utility functions for {@link Git}. */ export namespace GitUtils { /** * `true` if the argument is an option for renaming an existing branch in the repository. */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function isBranchRename(arg: any | undefined): arg is Git.Options.BranchCommand.Rename { - return !!arg && ('newName' in arg); + export function isBranchRename(arg: unknown): arg is Git.Options.BranchCommand.Rename { + return !!arg && typeof arg === 'object' && ('newName' in arg); } /** * `true` if the argument is an option for deleting an existing branch in the repository. */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function isBranchDelete(arg: any | undefined): arg is Git.Options.BranchCommand.Delete { - return !!arg && ('toDelete' in arg); + export function isBranchDelete(arg: unknown): arg is Git.Options.BranchCommand.Delete { + return !!arg && typeof arg === 'object' && ('toDelete' in arg); } /** * `true` if the argument is an option for creating a new branch in the repository. */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function isBranchCreate(arg: any | undefined): arg is Git.Options.BranchCommand.Create { - return !!arg && ('toCreate' in arg); + export function isBranchCreate(arg: unknown): arg is Git.Options.BranchCommand.Create { + return !!arg && typeof arg === 'object' && ('toCreate' in arg); } /** * `true` if the argument is an option for listing the branches in a repository. */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function isBranchList(arg: any | undefined): arg is Git.Options.BranchCommand.List { - return !!arg && ('type' in arg); + export function isBranchList(arg: unknown): arg is Git.Options.BranchCommand.List { + return !!arg && typeof arg === 'object' && ('type' in arg); } /** * `true` if the argument is an option for checking out a new local branch. */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function isBranchCheckout(arg: any | undefined): arg is Git.Options.Checkout.CheckoutBranch { - return !!arg && ('branch' in arg); + export function isBranchCheckout(arg: unknown): arg is Git.Options.Checkout.CheckoutBranch { + return !!arg && typeof arg === 'object' && ('branch' in arg); } /** * `true` if the argument is an option for checking out a working tree file. */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function isWorkingTreeFileCheckout(arg: any | undefined): arg is Git.Options.Checkout.WorkingTreeFile { - return !!arg && ('paths' in arg); + export function isWorkingTreeFileCheckout(arg: unknown): arg is Git.Options.Checkout.WorkingTreeFile { + return !!arg && typeof arg === 'object' && ('paths' in arg); } /** @@ -907,13 +901,11 @@ export namespace GitUtils { * `true` if the argument is an error indicating the absence of a local Git repository. * Otherwise, `false`. */ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function isRepositoryDoesNotExistError(error: any | undefined): boolean { + export function isRepositoryDoesNotExistError(error: unknown): boolean { // TODO this is odd here.This piece of code is already implementation specific, so this should go to the Git API. // But how can we ensure that the `any` type error is serializable? if (error instanceof Error && ('code' in error)) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - return (error).code === RepositoryDoesNotExistErrorCode; + return (error as { code: string }).code === RepositoryDoesNotExistErrorCode; } return false; } diff --git a/packages/markers/src/browser/marker-tree.ts b/packages/markers/src/browser/marker-tree.ts index 251862dbab9ce..8018bae409621 100644 --- a/packages/markers/src/browser/marker-tree.ts +++ b/packages/markers/src/browser/marker-tree.ts @@ -139,7 +139,7 @@ export interface MarkerInfoNode extends UriSelection, SelectableTreeNode, Expand severity?: DiagnosticSeverity; } export namespace MarkerInfoNode { - export function is(node: Object | undefined): node is MarkerInfoNode { + export function is(node: unknown): node is MarkerInfoNode { return ExpandableTreeNode.is(node) && UriSelection.is(node) && 'numberOfMarkers' in node; } } diff --git a/packages/markers/src/browser/problem/problem-selection.ts b/packages/markers/src/browser/problem/problem-selection.ts index 461256f60e189..39552b170de0a 100644 --- a/packages/markers/src/browser/problem/problem-selection.ts +++ b/packages/markers/src/browser/problem/problem-selection.ts @@ -23,8 +23,8 @@ export interface ProblemSelection { marker: Marker; } export namespace ProblemSelection { - export function is(arg: Object | undefined): arg is ProblemSelection { - return typeof arg === 'object' && ('marker' in arg) && ProblemMarker.is(arg['marker']); + export function is(arg: unknown): arg is ProblemSelection { + return !!arg && typeof arg === 'object' && ('marker' in arg) && ProblemMarker.is((arg as ProblemSelection).marker); } export class CommandHandler extends SelectionCommandHandler { diff --git a/packages/monaco/src/browser/monaco-indexed-db.ts b/packages/monaco/src/browser/monaco-indexed-db.ts index 4ba02c70ae2c8..3ee5ebc66a651 100644 --- a/packages/monaco/src/browser/monaco-indexed-db.ts +++ b/packages/monaco/src/browser/monaco-indexed-db.ts @@ -43,7 +43,7 @@ export interface MonacoThemeState { data: ThemeMix } export namespace MonacoThemeState { - export function is(state: Object | undefined): state is MonacoThemeState { + export function is(state: unknown): state is MonacoThemeState { return !!state && typeof state === 'object' && 'id' in state && 'label' in state && 'uiTheme' in state && 'data' in state; } } diff --git a/packages/monaco/src/browser/monaco-snippet-suggest-provider.ts b/packages/monaco/src/browser/monaco-snippet-suggest-provider.ts index 9e0a6d32f1981..6215a39aebaa7 100644 --- a/packages/monaco/src/browser/monaco-snippet-suggest-provider.ts +++ b/packages/monaco/src/browser/monaco-snippet-suggest-provider.ts @@ -249,8 +249,8 @@ export interface JsonSerializedSnippet { description: string; } export namespace JsonSerializedSnippet { - export function is(obj: Object | undefined): obj is JsonSerializedSnippet { - return typeof obj === 'object' && 'body' in obj && 'prefix' in obj; + export function is(obj: unknown): obj is JsonSerializedSnippet { + return !!obj && typeof obj === 'object' && 'body' in obj && 'prefix' in obj; } } diff --git a/packages/navigator/src/browser/navigator-tree.ts b/packages/navigator/src/browser/navigator-tree.ts index 7980baf0494ec..44ee4469e0a7c 100644 --- a/packages/navigator/src/browser/navigator-tree.ts +++ b/packages/navigator/src/browser/navigator-tree.ts @@ -113,7 +113,7 @@ export interface WorkspaceRootNode extends DirNode { } export namespace WorkspaceRootNode { - export function is(node: Object | undefined): node is WorkspaceRootNode { + export function is(node: unknown): node is WorkspaceRootNode { return DirNode.is(node) && WorkspaceNode.is(node.parent); } diff --git a/packages/navigator/src/browser/open-editors-widget/navigator-open-editors-tree-model.ts b/packages/navigator/src/browser/open-editors-widget/navigator-open-editors-tree-model.ts index 7a086321cae4c..c6ed0009ba6c2 100644 --- a/packages/navigator/src/browser/open-editors-widget/navigator-open-editors-tree-model.ts +++ b/packages/navigator/src/browser/open-editors-widget/navigator-open-editors-tree-model.ts @@ -38,7 +38,7 @@ export interface OpenEditorNode extends FileStatNode { }; export namespace OpenEditorNode { - export function is(node: object | undefined): node is OpenEditorNode { + export function is(node: unknown): node is OpenEditorNode { return FileStatNode.is(node) && 'widget' in node; } } diff --git a/packages/plugin-ext/src/common/plugin-api-rpc.ts b/packages/plugin-ext/src/common/plugin-api-rpc.ts index 532184f80ec88..1410c6a2ac5bd 100644 --- a/packages/plugin-ext/src/common/plugin-api-rpc.ts +++ b/packages/plugin-ext/src/common/plugin-api-rpc.ts @@ -732,7 +732,7 @@ export interface TreeViewSelection { treeItemId: string } export namespace TreeViewSelection { - export function is(arg: Object | any): arg is TreeViewSelection { + export function is(arg: unknown): arg is TreeViewSelection { return !!arg && typeof arg === 'object' && 'treeViewId' in arg && 'treeItemId' in arg; } } @@ -778,7 +778,7 @@ export interface ScmCommandArg { resourceStateHandle?: number } export namespace ScmCommandArg { - export function is(arg: Object | undefined): arg is ScmCommandArg { + export function is(arg: unknown): arg is ScmCommandArg { return !!arg && typeof arg === 'object' && 'sourceControlHandle' in arg; } } @@ -794,7 +794,7 @@ export interface ScmExt { } export namespace TimelineCommandArg { - export function is(arg: Object | undefined): arg is TimelineCommandArg { + export function is(arg: unknown): arg is TimelineCommandArg { return !!arg && typeof arg === 'object' && 'timelineHandle' in arg; } } @@ -813,7 +813,7 @@ export type DecorationData = [boolean, string, string, ThemeColor]; export interface DecorationReply { [id: number]: DecorationData; } export namespace CommentsCommandArg { - export function is(arg: Object | undefined): arg is CommentsCommandArg { + export function is(arg: unknown): arg is CommentsCommandArg { return !!arg && typeof arg === 'object' && 'commentControlHandle' in arg && 'commentThreadHandle' in arg && 'text' in arg && !('commentUniqueId' in arg); } } @@ -824,7 +824,7 @@ export interface CommentsCommandArg { } export namespace CommentsContextCommandArg { - export function is(arg: Object | undefined): arg is CommentsContextCommandArg { + export function is(arg: unknown): arg is CommentsContextCommandArg { return !!arg && typeof arg === 'object' && 'commentControlHandle' in arg && 'commentThreadHandle' in arg && 'commentUniqueId' in arg && !('text' in arg); } } @@ -835,7 +835,7 @@ export interface CommentsContextCommandArg { } export namespace CommentsEditCommandArg { - export function is(arg: Object | undefined): arg is CommentsEditCommandArg { + export function is(arg: unknown): arg is CommentsEditCommandArg { return !!arg && typeof arg === 'object' && 'commentControlHandle' in arg && 'commentThreadHandle' in arg && 'commentUniqueId' in arg && 'text' in arg; } } diff --git a/packages/plugin-ext/src/common/rpc-protocol.ts b/packages/plugin-ext/src/common/rpc-protocol.ts index e46c930a3c325..efd5b9503bee3 100644 --- a/packages/plugin-ext/src/common/rpc-protocol.ts +++ b/packages/plugin-ext/src/common/rpc-protocol.ts @@ -70,9 +70,8 @@ export namespace ConnectionClosedError { export function create(message: string = 'connection is closed'): ConnectionClosedError { return Object.assign(new Error(message), { code }); } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function is(error: any): error is ConnectionClosedError { - return !!error && typeof error === 'object' && 'code' in error && error['code'] === code; + export function is(error: unknown): error is ConnectionClosedError { + return !!error && typeof error === 'object' && 'code' in error && (error as ConnectionClosedError).code === code; } } @@ -469,8 +468,9 @@ enum SerializedObjectType { TEXT_BUFFER } -function isSerializedObject(obj: any): obj is SerializedObject { - return obj && obj.$type !== undefined && obj.data !== undefined; +function isSerializedObject(obj: unknown): obj is SerializedObject { + const serializedObject = obj as SerializedObject; + return !!obj && typeof obj === 'object' && serializedObject.$type !== undefined && serializedObject.data !== undefined; } export const enum MessageType { diff --git a/packages/plugin-ext/src/main/browser/view/tree-view-decorator-service.ts b/packages/plugin-ext/src/main/browser/view/tree-view-decorator-service.ts index ae079fb330d35..c6df32ad46596 100644 --- a/packages/plugin-ext/src/main/browser/view/tree-view-decorator-service.ts +++ b/packages/plugin-ext/src/main/browser/view/tree-view-decorator-service.ts @@ -32,9 +32,9 @@ export class TreeViewDecoratorAdapter extends FileTreeDecoratorAdapter { } } - protected isTreeItem(node: object | undefined): node is TreeItem & { resourceUri: Uri } { + protected isTreeItem(node: unknown): node is TreeItem & { resourceUri: Uri } { const candidate = node as TreeItem; - return !!candidate && 'resourceUri' in candidate && !!candidate.resourceUri; + return !!candidate && typeof node === 'object' && 'resourceUri' in candidate && !!candidate.resourceUri; } } diff --git a/packages/plugin-ext/src/plugin/languages/code-action.ts b/packages/plugin-ext/src/plugin/languages/code-action.ts index 37564bb07fe0e..9bbff9fe8ba81 100644 --- a/packages/plugin-ext/src/plugin/languages/code-action.ts +++ b/packages/plugin-ext/src/plugin/languages/code-action.ts @@ -145,20 +145,17 @@ export class CodeActionAdapter { return this.cacheId++; } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - private static _isCommand(smth: any): smth is theia.Command { - return typeof (smth).command === 'string'; + private static _isCommand(arg: unknown): arg is theia.Command { + return !!arg && typeof arg === 'object' && typeof (arg as theia.Command).command === 'string'; } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - private static _isSelection(obj: any): obj is Selection { - return ( - obj - && (typeof obj.selectionStartLineNumber === 'number') - && (typeof obj.selectionStartColumn === 'number') - && (typeof obj.positionLineNumber === 'number') - && (typeof obj.positionColumn === 'number') - ); + private static _isSelection(obj: unknown): obj is Selection { + const selection = obj as Selection; + return !!obj && typeof obj === 'object' + && typeof selection.selectionStartLineNumber === 'number' + && typeof selection.selectionStartColumn === 'number' + && typeof selection.positionLineNumber === 'number' + && typeof selection.positionColumn === 'number'; } } diff --git a/packages/plugin-ext/src/plugin/languages/document-highlight.ts b/packages/plugin-ext/src/plugin/languages/document-highlight.ts index bc7a95ded2bbd..152de8d002dfa 100644 --- a/packages/plugin-ext/src/plugin/languages/document-highlight.ts +++ b/packages/plugin-ext/src/plugin/languages/document-highlight.ts @@ -55,8 +55,7 @@ export class DocumentHighlightAdapter { }); } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - private isDocumentHighlightArray(array: any): array is types.DocumentHighlight[] { + private isDocumentHighlightArray(array: unknown): array is types.DocumentHighlight[] { return Array.isArray(array) && array.length > 0 && array[0] instanceof types.DocumentHighlight; } } diff --git a/packages/plugin-ext/src/plugin/languages/util.ts b/packages/plugin-ext/src/plugin/languages/util.ts index 6c38a6bb80743..2918f5edcf0a2 100644 --- a/packages/plugin-ext/src/plugin/languages/util.ts +++ b/packages/plugin-ext/src/plugin/languages/util.ts @@ -17,12 +17,10 @@ import * as theia from '@theia/plugin'; import * as types from '../types-impl'; -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export function isLocationArray(array: any): array is types.Location[] { +export function isLocationArray(array: unknown): array is types.Location[] { return Array.isArray(array) && array.length > 0 && array[0] instanceof types.Location; } -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export function isDefinitionLinkArray(array: any): array is theia.DefinitionLink[] { +export function isDefinitionLinkArray(array: unknown): array is theia.DefinitionLink[] { return Array.isArray(array) && array.length > 0 && array[0].hasOwnProperty('targetUri') && array[0].hasOwnProperty('targetRange'); } diff --git a/packages/plugin-ext/src/plugin/type-converters.ts b/packages/plugin-ext/src/plugin/type-converters.ts index ae400b0db32f9..581080ac3c80b 100644 --- a/packages/plugin-ext/src/plugin/type-converters.ts +++ b/packages/plugin-ext/src/plugin/type-converters.ts @@ -137,9 +137,8 @@ export function toPosition(position: Position): types.Position { return new types.Position(position.lineNumber - 1, position.column - 1); } -// eslint-disable-next-line @typescript-eslint/no-explicit-any -function isDecorationOptions(something: any): something is theia.DecorationOptions { - return (typeof something.range !== 'undefined'); +function isDecorationOptions(arg: unknown): arg is theia.DecorationOptions { + return !!arg && typeof arg === 'object' && typeof (arg as theia.DecorationOptions).range !== 'undefined'; } export function isDecorationOptionsArr(something: theia.Range[] | theia.DecorationOptions[]): something is theia.DecorationOptions[] { @@ -182,11 +181,10 @@ interface Codeblock { value: string; } -// eslint-disable-next-line @typescript-eslint/no-explicit-any -function isCodeblock(thing: any): thing is Codeblock { - return thing && typeof thing === 'object' - && typeof (thing).language === 'string' - && typeof (thing).value === 'string'; +function isCodeblock(arg: unknown): arg is Codeblock { + return !!arg && typeof arg === 'object' + && typeof (arg as Codeblock).language === 'string' + && typeof (arg as Codeblock).value === 'string'; } export function fromMarkdown(markup: theia.MarkdownString | theia.MarkedString): MarkdownStringDTO { @@ -618,64 +616,58 @@ export function toSymbolTag(kind: model.SymbolTag): types.SymbolTag { } } -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export function isModelLocation(thing: any): thing is model.Location { - if (!thing) { - return false; - } - return isModelRange((thing).range) && - isUriComponents((thing).uri); -} - -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export function isModelRange(thing: any): thing is model.Range { - if (!thing) { +export function isModelLocation(arg: unknown): arg is model.Location { + if (!arg) { return false; } - return (('startLineNumber' in thing) && typeof thing.startLineNumber === 'number') && - (('startColumn' in thing) && typeof thing.startColumn === 'number') && - (('endLineNumber' in thing) && typeof thing.endLineNumber === 'number') && - (('endColumn' in thing) && typeof thing.endColumn === 'number'); + return !!arg && + typeof arg === 'object' && + isModelRange((arg as model.Location).range) && + isUriComponents((arg as model.Location).uri); } -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export function isUriComponents(thing: any): thing is UriComponents { - if (!thing) { - return false; - } - return (('scheme' in thing) && typeof thing.scheme === 'string') && - (('path' in thing) && typeof thing.path === 'string') && - (('query' in thing) && typeof thing.query === 'string') && - (('fragment' in thing) && typeof thing.fragment === 'string'); +export function isModelRange(arg: unknown): arg is model.Range { + const range = arg as model.Range; + return !!arg && typeof arg === 'object' && + typeof range.startLineNumber === 'number' && + typeof range.startColumn === 'number' && + typeof range.endLineNumber === 'number' && + typeof range.endColumn === 'number'; } // eslint-disable-next-line @typescript-eslint/no-explicit-any -export function isModelCallHierarchyItem(thing: any): thing is model.CallHierarchyItem { - if (!thing) { - return false; - } - return isModelRange(thing.range) - && isModelRange(thing.selectionRange) - && isUriComponents(thing.uri) - && !!thing.name; -} - -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export function isModelCallHierarchyIncomingCall(thing: any): thing is model.CallHierarchyIncomingCall { - if (!thing) { - return false; - } - const maybeIncomingCall = thing as model.CallHierarchyIncomingCall; - return 'from' in maybeIncomingCall && 'fromRanges' in maybeIncomingCall && isModelCallHierarchyItem(maybeIncomingCall.from); -} - -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export function isModelCallHierarchyOutgoingCall(thing: any): thing is model.CallHierarchyOutgoingCall { - if (!thing) { - return false; - } - const maybeOutgoingCall = thing as model.CallHierarchyOutgoingCall; - return 'to' in maybeOutgoingCall && 'fromRanges' in maybeOutgoingCall && isModelCallHierarchyItem(maybeOutgoingCall.to); +export function isUriComponents(arg: unknown): arg is UriComponents { + const uriComponents = arg as UriComponents; + return !!arg && typeof arg === 'object' && + typeof uriComponents.scheme === 'string' && + typeof uriComponents.path === 'string' && + typeof uriComponents.query === 'string' && + typeof uriComponents.fragment === 'string'; +} + +export function isModelCallHierarchyItem(arg: unknown): arg is model.CallHierarchyItem { + const item = arg as model.CallHierarchyItem; + return !!item && typeof item === 'object' + && isModelRange(item.range) + && isModelRange(item.selectionRange) + && isUriComponents(item.uri) + && !!item.name; +} + +export function isModelCallHierarchyIncomingCall(arg: unknown): arg is model.CallHierarchyIncomingCall { + const maybeIncomingCall = arg as model.CallHierarchyIncomingCall; + return !!arg && typeof arg === 'object' && + 'from' in maybeIncomingCall && + 'fromRanges' in maybeIncomingCall && + isModelCallHierarchyItem(maybeIncomingCall.from); +} + +export function isModelCallHierarchyOutgoingCall(arg: unknown): arg is model.CallHierarchyOutgoingCall { + const maybeOutgoingCall = arg as model.CallHierarchyOutgoingCall; + return !!arg && typeof arg === 'object' && + 'to' in maybeOutgoingCall && + 'fromRanges' in maybeOutgoingCall && + isModelCallHierarchyItem(maybeOutgoingCall.to); } export function toLocation(value: model.Location): types.Location { diff --git a/packages/plugin-ext/src/plugin/types-impl.ts b/packages/plugin-ext/src/plugin/types-impl.ts index 5ababe64d05ac..d9243b531cb56 100644 --- a/packages/plugin-ext/src/plugin/types-impl.ts +++ b/packages/plugin-ext/src/plugin/types-impl.ts @@ -20,7 +20,6 @@ *--------------------------------------------------------------------------------------------*/ /* eslint-disable no-null/no-null */ -/* eslint-disable @typescript-eslint/no-explicit-any */ import { UUID } from '@theia/core/shared/@phosphor/coreutils'; import { illegalArgument } from '../common/errors'; @@ -38,6 +37,7 @@ import { es5ClassCompat } from '../common/types'; * A reviver that takes URI's transferred via JSON.stringify() and makes * instances of our local plugin API URI class (below) */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any export function reviver(key: string | undefined, value: any): any { const revived = ObjectsTransferrer.reviver(key, value); if (CodeURI.isUri(revived)) { @@ -423,7 +423,7 @@ export class Position { return false; } - toJSON(): any { + toJSON(): unknown { return { line: this.line, character: this.character }; } } @@ -546,19 +546,17 @@ export class Range { return new Range(start, end); } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - static isRange(thing: any): thing is theia.Range { + static isRange(thing: unknown): thing is theia.Range { if (thing instanceof Range) { return true; } - if (!thing) { - return false; - } - return Position.isPosition((thing).start) - && Position.isPosition((thing).end); + const range = thing as theia.Range; + return !!thing && typeof thing === 'object' + && Position.isPosition(range.start) + && Position.isPosition(range.end); } - toJSON(): any { + toJSON(): unknown { return [this.start, this.end]; } } @@ -1618,8 +1616,8 @@ export class FileSystemError extends Error { // workaround when extending builtin objects and when compiling to ES5, see: // https://github.com/Microsoft/TypeScript-wiki/blob/master/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work - if (typeof (Object).setPrototypeOf === 'function') { - (Object).setPrototypeOf(this, FileSystemError.prototype); + if (typeof Object.setPrototypeOf === 'function') { + Object.setPrototypeOf(this, FileSystemError.prototype); } if (typeof Error.captureStackTrace === 'function' && typeof terminator === 'function') { @@ -2537,7 +2535,7 @@ export class SemanticTokensLegend { } } -function isStrArrayOrUndefined(arg: any): arg is string[] | undefined { +function isStrArrayOrUndefined(arg: unknown): arg is string[] | undefined { return ((typeof arg === 'undefined') || (Array.isArray(arg) && arg.every(e => typeof e === 'string'))); } @@ -2575,7 +2573,7 @@ export class SemanticTokensBuilder { public push(line: number, char: number, length: number, tokenType: number, tokenModifiers?: number): void; public push(range: Range, tokenType: string, tokenModifiers?: string[]): void; - public push(arg0: any, arg1: any, arg2: any, arg3?: any, arg4?: any): void { + public push(arg0: number | Range, arg1: number | string, arg2?: number | string[], arg3?: number, arg4?: number): void { if (typeof arg0 === 'number' && typeof arg1 === 'number' && typeof arg2 === 'number' && typeof arg3 === 'number' && (typeof arg4 === 'number' || typeof arg4 === 'undefined')) { if (typeof arg4 === 'undefined') { diff --git a/packages/preferences/src/browser/views/components/preference-file-input.ts b/packages/preferences/src/browser/views/components/preference-file-input.ts index 9187cbc5c112f..4510a1cc26731 100644 --- a/packages/preferences/src/browser/views/components/preference-file-input.ts +++ b/packages/preferences/src/browser/views/components/preference-file-input.ts @@ -30,9 +30,8 @@ export interface FileNodeTypeDetails { } export namespace FileNodeTypeDetails { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function is(typeDetails?: any): typeDetails is FileNodeTypeDetails { - return !!typeDetails && !!typeDetails.isFilepath; + export function is(typeDetails?: unknown): typeDetails is FileNodeTypeDetails { + return !!typeDetails && typeof typeDetails === 'object' && !!(typeDetails as FileNodeTypeDetails).isFilepath; } } diff --git a/packages/preview/src/browser/preview-handler.ts b/packages/preview/src/browser/preview-handler.ts index 97e1187ff1c3b..f415882e7ee0c 100644 --- a/packages/preview/src/browser/preview-handler.ts +++ b/packages/preview/src/browser/preview-handler.ts @@ -35,8 +35,8 @@ export interface RenderContentParams { } export namespace RenderContentParams { - export function is(params: object | undefined): params is RenderContentParams { - return !!params && 'content' in params && 'originUri' in params; + export function is(params: unknown): params is RenderContentParams { + return !!params && typeof params === 'object' && 'content' in params && 'originUri' in params; } } diff --git a/packages/process/src/node/process.ts b/packages/process/src/node/process.ts index ccd8ec0342bdf..a234d11864e77 100644 --- a/packages/process/src/node/process.ts +++ b/packages/process/src/node/process.ts @@ -192,9 +192,8 @@ export abstract class Process { this.logger.error(error); } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - protected isForkOptions(options: any): options is ForkOptions { - return !!options && !!options.modulePath; + protected isForkOptions(options: unknown): options is ForkOptions { + return !!options && typeof options === 'object' && !!(options as ForkOptions).modulePath; } protected readonly initialCwd: string; diff --git a/packages/property-view/src/browser/resource-property-view/resource-property-view-tree-items.ts b/packages/property-view/src/browser/resource-property-view/resource-property-view-tree-items.ts index fc135e74d8af8..e3546cdf81334 100644 --- a/packages/property-view/src/browser/resource-property-view/resource-property-view-tree-items.ts +++ b/packages/property-view/src/browser/resource-property-view/resource-property-view-tree-items.ts @@ -22,7 +22,7 @@ export interface ResourcePropertiesRoot extends CompositeTreeNode { children: ResourcePropertiesCategoryNode[]; } export namespace ResourcePropertiesRoot { - export function is(node: Object | undefined): node is ResourcePropertiesRoot { + export function is(node: unknown): node is ResourcePropertiesRoot { return CompositeTreeNode.is(node) && node.id === ROOT_ID; } } diff --git a/packages/scm-extra/src/browser/history/scm-history-widget.tsx b/packages/scm-extra/src/browser/history/scm-history-widget.tsx index a5f9629ad5be2..bd43736372245 100644 --- a/packages/scm-extra/src/browser/history/scm-history-widget.tsx +++ b/packages/scm-extra/src/browser/history/scm-history-widget.tsx @@ -46,9 +46,8 @@ export interface ScmCommitNode { } export namespace ScmCommitNode { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function is(node: any): node is ScmCommitNode { - return !!node && 'commitDetails' in node && 'expanded' in node && 'selected' in node; + export function is(node: unknown): node is ScmCommitNode { + return !!node && typeof node === 'object' && 'commitDetails' in node && 'expanded' in node && 'selected' in node; } } diff --git a/packages/scm-extra/src/browser/scm-file-change-node.ts b/packages/scm-extra/src/browser/scm-file-change-node.ts index f3d17b08454be..a42d7b393e0aa 100644 --- a/packages/scm-extra/src/browser/scm-file-change-node.ts +++ b/packages/scm-extra/src/browser/scm-file-change-node.ts @@ -23,8 +23,8 @@ export interface ScmFileChangeNode { selected?: boolean; } export namespace ScmFileChangeNode { - export function is(node: Object | undefined): node is ScmFileChangeNode { - return !!node && 'fileChange' in node && 'commitId' in node; + export function is(node: unknown): node is ScmFileChangeNode { + return !!node && typeof node === 'object' && 'fileChange' in node && 'commitId' in node; } } diff --git a/packages/search-in-workspace/src/browser/search-in-workspace-result-tree-widget.tsx b/packages/search-in-workspace/src/browser/search-in-workspace-result-tree-widget.tsx index 04760c9bc10cb..0149bac766cf4 100644 --- a/packages/search-in-workspace/src/browser/search-in-workspace-result-tree-widget.tsx +++ b/packages/search-in-workspace/src/browser/search-in-workspace-result-tree-widget.tsx @@ -59,8 +59,7 @@ export interface SearchInWorkspaceRoot extends CompositeTreeNode { children: SearchInWorkspaceRootFolderNode[]; } export namespace SearchInWorkspaceRoot { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function is(node: any): node is SearchInWorkspaceRoot { + export function is(node: unknown): node is SearchInWorkspaceRoot { return CompositeTreeNode.is(node) && node.id === ROOT_ID; } } @@ -74,8 +73,7 @@ export interface SearchInWorkspaceRootFolderNode extends ExpandableTreeNode, Sel uri: URI; } export namespace SearchInWorkspaceRootFolderNode { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function is(node: any): node is SearchInWorkspaceRootFolderNode { + export function is(node: unknown): node is SearchInWorkspaceRootFolderNode { return ExpandableTreeNode.is(node) && SelectableTreeNode.is(node) && 'path' in node && 'folderUri' in node && !('fileUri' in node); } } @@ -90,8 +88,7 @@ export interface SearchInWorkspaceFileNode extends ExpandableTreeNode, Selectabl uri: URI; } export namespace SearchInWorkspaceFileNode { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function is(node: any): node is SearchInWorkspaceFileNode { + export function is(node: unknown): node is SearchInWorkspaceFileNode { return ExpandableTreeNode.is(node) && SelectableTreeNode.is(node) && 'path' in node && 'fileUri' in node && !('folderUri' in node); } } @@ -100,8 +97,7 @@ export interface SearchInWorkspaceResultLineNode extends SelectableTreeNode, Sea parent: SearchInWorkspaceFileNode } export namespace SearchInWorkspaceResultLineNode { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function is(node: any): node is SearchInWorkspaceResultLineNode { + export function is(node: unknown): node is SearchInWorkspaceResultLineNode { return SelectableTreeNode.is(node) && 'line' in node && 'character' in node && 'lineText' in node; } } diff --git a/packages/task/src/browser/task-frontend-contribution.ts b/packages/task/src/browser/task-frontend-contribution.ts index 3bd7144acd7f0..7e2cc28703dbe 100644 --- a/packages/task/src/browser/task-frontend-contribution.ts +++ b/packages/task/src/browser/task-frontend-contribution.ts @@ -244,8 +244,7 @@ export class TaskFrontendContribution implements CommandContribution, MenuContri TaskCommands.TASK_RUN_BUILD, { isEnabled: () => this.workspaceService.opened, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - execute: (...args: any[]) => + execute: () => this.quickOpenTask.runBuildOrTestTask('build') } ); @@ -253,8 +252,7 @@ export class TaskFrontendContribution implements CommandContribution, MenuContri TaskCommands.TASK_RUN_TEST, { isEnabled: () => this.workspaceService.opened, - // eslint-disable-next-line @typescript-eslint/no-explicit-any - execute: (...args: any[]) => + execute: () => this.quickOpenTask.runBuildOrTestTask('test') } ); diff --git a/packages/terminal/src/browser/terminal-preferences.ts b/packages/terminal/src/browser/terminal-preferences.ts index e05f1a77bfe5e..48913d1676a8b 100644 --- a/packages/terminal/src/browser/terminal-preferences.ts +++ b/packages/terminal/src/browser/terminal-preferences.ts @@ -191,8 +191,7 @@ export type CursorStyleVSCode = CursorStyle | 'line'; export type TerminalRendererType = 'canvas' | 'dom'; export type ConfirmOnExitType = 'never' | 'always' | 'hasChildProcesses'; export const DEFAULT_TERMINAL_RENDERER_TYPE = 'canvas'; -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export function isTerminalRendererType(arg: any): arg is TerminalRendererType { +export function isTerminalRendererType(arg: unknown): arg is TerminalRendererType { return typeof arg === 'string' && (arg === 'canvas' || arg === 'dom'); } diff --git a/packages/typehierarchy/src/browser/tree/typehierarchy-tree.ts b/packages/typehierarchy/src/browser/tree/typehierarchy-tree.ts index e62eb2f92e05d..58c8c7578eb15 100644 --- a/packages/typehierarchy/src/browser/tree/typehierarchy-tree.ts +++ b/packages/typehierarchy/src/browser/tree/typehierarchy-tree.ts @@ -97,8 +97,7 @@ export namespace TypeHierarchyTree { export function is(node: TreeNode | undefined): node is RootNode { if (Node.is(node) && 'direction' in node) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const { direction } = (node as any); + const { direction } = (node as RootNode); return direction === TypeHierarchyDirection.Children || direction === TypeHierarchyDirection.Parents; } return false; @@ -122,8 +121,7 @@ export namespace TypeHierarchyTree { export function is(node: TreeNode | undefined): node is Node { if (!!node && 'resolved' in node && 'item' in node) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const { resolved, item } = (node as any); + const { resolved, item } = (node as Node); return typeof resolved === 'boolean' && !!item; } return false; diff --git a/packages/vsx-registry/src/browser/vsx-extension.tsx b/packages/vsx-registry/src/browser/vsx-extension.tsx index de85d963b6401..7dcab93a0b951 100644 --- a/packages/vsx-registry/src/browser/vsx-extension.tsx +++ b/packages/vsx-registry/src/browser/vsx-extension.tsx @@ -442,8 +442,7 @@ export namespace AbstractVSXExtensionComponent { } const downloadFormatter = new Intl.NumberFormat(); -// eslint-disable-next-line @typescript-eslint/no-explicit-any -const downloadCompactFormatter = new Intl.NumberFormat(undefined, { notation: 'compact', compactDisplay: 'short' } as any); +const downloadCompactFormatter = new Intl.NumberFormat(undefined, { notation: 'compact', compactDisplay: 'short' }); export namespace VSXExtensionComponent { export interface Props extends AbstractVSXExtensionComponent.Props { diff --git a/packages/workspace/src/browser/workspace-schema-updater.ts b/packages/workspace/src/browser/workspace-schema-updater.ts index 0523641b5319c..8556243d92372 100644 --- a/packages/workspace/src/browser/workspace-schema-updater.ts +++ b/packages/workspace/src/browser/workspace-schema-updater.ts @@ -114,13 +114,12 @@ export class WorkspaceSchemaUpdater implements JsonSchemaContribution { export type WorkspaceSchema = Required>; export namespace WorkspaceSchema { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export const is = (candidate: any): candidate is WorkspaceSchema => !!candidate + export const is = (candidate: unknown): candidate is WorkspaceSchema => !!candidate && typeof candidate === 'object' && 'properties' in candidate - && typeof candidate.properties === 'object' + && typeof (candidate as WorkspaceSchema).properties === 'object' && 'required' in candidate - && Array.isArray(candidate.required); + && Array.isArray((candidate as WorkspaceSchema).required); } export const workspaceSchemaId = 'vscode://schemas/workspace'; diff --git a/packages/workspace/src/browser/workspace-service.ts b/packages/workspace/src/browser/workspace-service.ts index 7f6a1d55773e7..603c02095af68 100644 --- a/packages/workspace/src/browser/workspace-service.ts +++ b/packages/workspace/src/browser/workspace-service.ts @@ -709,12 +709,10 @@ export interface WorkspaceData { export namespace WorkspaceData { const validateSchema = new Ajv().compile(workspaceSchema); - // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function is(data: any): data is WorkspaceData { + export function is(data: unknown): data is WorkspaceData { return !!validateSchema(data); } - // eslint-disable-next-line @typescript-eslint/no-explicit-any export function buildWorkspaceData(folders: string[] | FileStat[], additionalFields?: Partial): WorkspaceData { let roots: string[] = []; if (folders.length > 0) { diff --git a/packages/workspace/src/node/default-workspace-server.ts b/packages/workspace/src/node/default-workspace-server.ts index 2bcd6649bc3bc..8be2f62899011 100644 --- a/packages/workspace/src/node/default-workspace-server.ts +++ b/packages/workspace/src/node/default-workspace-server.ts @@ -231,14 +231,12 @@ namespace RecentWorkspacePathsData { * * Returns undefined if the given `data` does not contain a `recentRoots` array property. */ - export function create(data: Object | undefined): RecentWorkspacePathsData | undefined { - // eslint-disable-next-line @typescript-eslint/no-explicit-any, no-null/no-null - if (typeof data !== 'object' || data === null || !Array.isArray((data as any)['recentRoots'])) { + export function create(data: unknown): RecentWorkspacePathsData | undefined { + if (typeof data !== 'object' || !data || !Array.isArray((data as RecentWorkspacePathsData).recentRoots)) { return; } return { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - recentRoots: (data as any)['recentRoots'].filter((root: unknown) => typeof root === 'string') + recentRoots: (data as RecentWorkspacePathsData).recentRoots.filter(root => typeof root === 'string') }; } }