diff --git a/eslint.config.js b/eslint.config.js index 8ef6af01ba0..13d50038510 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -363,46 +363,30 @@ export default tseslint.config( // Base 'src/vs/base/browser/dom.ts', 'src/vs/base/browser/mouseEvent.ts', - 'src/vs/base/browser/pixelRatio.ts', - 'src/vs/base/browser/trustedTypes.ts', - 'src/vs/base/browser/webWorkerFactory.ts', - 'src/vs/base/node/osDisplayProtocolInfo.ts', - 'src/vs/base/node/osReleaseInfo.ts', 'src/vs/base/node/processes.ts', 'src/vs/base/common/arrays.ts', 'src/vs/base/common/async.ts', - 'src/vs/base/common/collections.ts', 'src/vs/base/common/console.ts', - 'src/vs/base/common/controlFlow.ts', 'src/vs/base/common/decorators.ts', - 'src/vs/base/common/equals.ts', 'src/vs/base/common/errorMessage.ts', 'src/vs/base/common/errors.ts', 'src/vs/base/common/event.ts', 'src/vs/base/common/hotReload.ts', 'src/vs/base/common/hotReloadHelpers.ts', - 'src/vs/base/common/iterator.ts', 'src/vs/base/common/json.ts', 'src/vs/base/common/jsonSchema.ts', 'src/vs/base/common/lifecycle.ts', 'src/vs/base/common/map.ts', 'src/vs/base/common/marshalling.ts', - 'src/vs/base/common/network.ts', - 'src/vs/base/common/oauth.ts', 'src/vs/base/common/objects.ts', 'src/vs/base/common/performance.ts', 'src/vs/base/common/platform.ts', 'src/vs/base/common/processes.ts', - 'src/vs/base/common/resourceTree.ts', - 'src/vs/base/common/strings.ts', 'src/vs/base/common/types.ts', 'src/vs/base/common/uriIpc.ts', 'src/vs/base/common/verifier.ts', 'src/vs/base/common/observableInternal/base.ts', 'src/vs/base/common/observableInternal/changeTracker.ts', - 'src/vs/base/common/observableInternal/debugLocation.ts', - 'src/vs/base/common/observableInternal/debugName.ts', - 'src/vs/base/common/observableInternal/map.ts', 'src/vs/base/common/observableInternal/set.ts', 'src/vs/base/common/observableInternal/transaction.ts', 'src/vs/base/common/worker/webWorkerBootstrap.ts', @@ -452,8 +436,6 @@ export default tseslint.config( 'src/vs/base/common/observableInternal/logging/debugger/rpc.ts', 'src/vs/base/test/browser/ui/grid/util.ts', // Platform - 'src/vs/platform/accessibility/browser/accessibleView.ts', - 'src/vs/platform/accessibility/common/accessibility.ts', 'src/vs/platform/browserElements/electron-main/nativeBrowserElementsMainService.ts', 'src/vs/platform/commands/common/commands.ts', 'src/vs/platform/configuration/common/configuration.ts', @@ -503,15 +485,12 @@ export default tseslint.config( 'src/vs/platform/observable/common/wrapInHotClass.ts', 'src/vs/platform/observable/common/wrapInReloadableClass.ts', 'src/vs/platform/policy/common/policyIpc.ts', - 'src/vs/platform/policy/node/nativePolicyService.ts', 'src/vs/platform/profiling/common/profilingTelemetrySpec.ts', 'src/vs/platform/quickinput/browser/quickInputActions.ts', 'src/vs/platform/quickinput/common/quickInput.ts', 'src/vs/platform/registry/common/platform.ts', 'src/vs/platform/remote/browser/browserSocketFactory.ts', 'src/vs/platform/remote/browser/remoteAuthorityResolverService.ts', - 'src/vs/platform/remote/common/electronRemoteResources.ts', - 'src/vs/platform/remote/common/managedSocket.ts', 'src/vs/platform/remote/common/remoteAgentConnection.ts', 'src/vs/platform/remote/common/remoteAuthorityResolver.ts', 'src/vs/platform/remote/electron-browser/electronRemoteResourceLoader.ts', diff --git a/src/vs/base/browser/pixelRatio.ts b/src/vs/base/browser/pixelRatio.ts index 7ff456e5aa3..d2d93b66f30 100644 --- a/src/vs/base/browser/pixelRatio.ts +++ b/src/vs/base/browser/pixelRatio.ts @@ -7,6 +7,14 @@ import { getWindowId, onDidUnregisterWindow } from './dom.js'; import { Emitter, Event } from '../common/event.js'; import { Disposable, markAsSingleton } from '../common/lifecycle.js'; +type BackingStoreContext = CanvasRenderingContext2D & { + webkitBackingStorePixelRatio?: number; + mozBackingStorePixelRatio?: number; + msBackingStorePixelRatio?: number; + oBackingStorePixelRatio?: number; + backingStorePixelRatio?: number; +}; + /** * See https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio#monitoring_screen_resolution_or_zoom_level_changes */ @@ -67,13 +75,13 @@ class PixelRatioMonitorImpl extends Disposable implements IPixelRatioMonitor { } private _getPixelRatio(targetWindow: Window): number { - const ctx: any = document.createElement('canvas').getContext('2d'); + const ctx = document.createElement('canvas').getContext('2d') as BackingStoreContext | null; const dpr = targetWindow.devicePixelRatio || 1; - const bsr = ctx.webkitBackingStorePixelRatio || - ctx.mozBackingStorePixelRatio || - ctx.msBackingStorePixelRatio || - ctx.oBackingStorePixelRatio || - ctx.backingStorePixelRatio || 1; + const bsr = ctx?.webkitBackingStorePixelRatio || + ctx?.mozBackingStorePixelRatio || + ctx?.msBackingStorePixelRatio || + ctx?.oBackingStorePixelRatio || + ctx?.backingStorePixelRatio || 1; return dpr / bsr; } } diff --git a/src/vs/base/browser/trustedTypes.ts b/src/vs/base/browser/trustedTypes.ts index ac3fb0eea3b..310ce79f0f9 100644 --- a/src/vs/base/browser/trustedTypes.ts +++ b/src/vs/base/browser/trustedTypes.ts @@ -24,7 +24,7 @@ export function createTrustedTypesPolicy; +}; + // Reuse the trusted types policy defined from worker bootstrap // when available. // Refs https://github.com/microsoft/vscode/issues/222193 let ttPolicy: ReturnType; -// eslint-disable-next-line local/code-no-any-casts -if (typeof self === 'object' && self.constructor && self.constructor.name === 'DedicatedWorkerGlobalScope' && (globalThis as any).workerttPolicy !== undefined) { - // eslint-disable-next-line local/code-no-any-casts - ttPolicy = (globalThis as any).workerttPolicy; +const workerGlobalThis = globalThis as WorkerGlobalWithPolicy; +if (typeof self === 'object' && self.constructor && self.constructor.name === 'DedicatedWorkerGlobalScope' && workerGlobalThis.workerttPolicy !== undefined) { + ttPolicy = workerGlobalThis.workerttPolicy; } else { ttPolicy = createTrustedTypesPolicy('defaultWorkerFactory', { createScriptURL: value => value }); } @@ -130,7 +133,7 @@ class WebWorker extends Disposable implements IWebWorker { private readonly _onMessage = this._register(new Emitter()); public readonly onMessage = this._onMessage.event; - private readonly _onError = this._register(new Emitter()); + private readonly _onError = this._register(new Emitter()); public readonly onError = this._onError.event; constructor(descriptorOrWorker: WebWorkerDescriptor | Worker | Promise) { diff --git a/src/vs/base/common/arrays.ts b/src/vs/base/common/arrays.ts index 1af1865d8ab..a7b52b435bd 100644 --- a/src/vs/base/common/arrays.ts +++ b/src/vs/base/common/arrays.ts @@ -202,8 +202,8 @@ export function forEachWithNeighbors(arr: T[], f: (before: T | undefined, ele } } -export function concatArrays(...arrays: TArr): TArr[number][number][] { - return ([] as any[]).concat(...arrays); +export function concatArrays(...arrays: T): T[number][number][] { + return [].concat(...arrays); } interface IMutableSplice extends ISplice { diff --git a/src/vs/base/common/collections.ts b/src/vs/base/common/collections.ts index 845c5d9a2a9..f64ad848bf4 100644 --- a/src/vs/base/common/collections.ts +++ b/src/vs/base/common/collections.ts @@ -96,7 +96,7 @@ export function intersection(setA: Set, setB: Iterable): Set { } export class SetWithKey implements Set { - private _map = new Map(); + private _map = new Map(); constructor(values: T[], private toKey: (t: T) => unknown) { for (const value of values) { @@ -142,7 +142,7 @@ export class SetWithKey implements Set { this._map.clear(); } - forEach(callbackfn: (value: T, value2: T, set: Set) => void, thisArg?: any): void { + forEach(callbackfn: (value: T, value2: T, set: Set) => void, thisArg?: unknown): void { this._map.forEach(entry => callbackfn.call(thisArg, entry, entry, this)); } diff --git a/src/vs/base/common/controlFlow.ts b/src/vs/base/common/controlFlow.ts index 35f860a222d..8fc6b19d3b1 100644 --- a/src/vs/base/common/controlFlow.ts +++ b/src/vs/base/common/controlFlow.ts @@ -53,9 +53,8 @@ export class ReentrancyBarrier { return this._isOccupied; } - public makeExclusiveOrSkip(fn: TFunction): TFunction { - // eslint-disable-next-line local/code-no-any-casts - return ((...args: any[]) => { + public makeExclusiveOrSkip(fn: (...args: TArgs) => void): (...args: TArgs) => void { + return ((...args: TArgs) => { if (this._isOccupied) { return; } @@ -65,6 +64,6 @@ export class ReentrancyBarrier { } finally { this._isOccupied = false; } - }) as any; + }); } } diff --git a/src/vs/base/common/equals.ts b/src/vs/base/common/equals.ts index df2db9256f1..88f9d2c36c6 100644 --- a/src/vs/base/common/equals.ts +++ b/src/vs/base/common/equals.ts @@ -10,7 +10,7 @@ export type EqualityComparer = (a: T, b: T) => boolean; /** * Compares two items for equality using strict equality. */ -export const strictEquals: EqualityComparer = (a, b) => a === b; +export const strictEquals = (a: T, b: T): boolean => a === b; /** * Checks if the items of two arrays are equal. diff --git a/src/vs/base/common/iterator.ts b/src/vs/base/common/iterator.ts index 59d92ca3994..54db9a8c5b7 100644 --- a/src/vs/base/common/iterator.ts +++ b/src/vs/base/common/iterator.ts @@ -7,13 +7,13 @@ import { isIterable } from './types.js'; export namespace Iterable { - export function is(thing: unknown): thing is Iterable { + export function is(thing: unknown): thing is Iterable { return !!thing && typeof thing === 'object' && typeof (thing as Iterable)[Symbol.iterator] === 'function'; } - const _empty: Iterable = Object.freeze([]); - export function empty(): Iterable { - return _empty; + const _empty: Iterable = Object.freeze([]); + export function empty(): Iterable { + return _empty as Iterable; } export function* single(element: T): Iterable { @@ -29,7 +29,7 @@ export namespace Iterable { } export function from(iterable: Iterable | undefined | null): Iterable { - return iterable || _empty; + return iterable ?? (_empty as Iterable); } export function* reverse(array: ReadonlyArray): Iterable { diff --git a/src/vs/base/common/network.ts b/src/vs/base/common/network.ts index 5a9ba7fd940..e47b42672fb 100644 --- a/src/vs/base/common/network.ts +++ b/src/vs/base/common/network.ts @@ -418,8 +418,7 @@ export namespace COI { * isn't enabled the current context */ export function addSearchParam(urlOrSearch: URLSearchParams | Record, coop: boolean, coep: boolean): void { - // eslint-disable-next-line local/code-no-any-casts - if (!(globalThis).crossOriginIsolated) { + if (!(globalThis as typeof globalThis & { crossOriginIsolated?: boolean }).crossOriginIsolated) { // depends on the current context being COI return; } diff --git a/src/vs/base/common/oauth.ts b/src/vs/base/common/oauth.ts index c808bf818b9..dceb75395b2 100644 --- a/src/vs/base/common/oauth.ts +++ b/src/vs/base/common/oauth.ts @@ -1080,7 +1080,7 @@ export function scopesMatch(scopes1: readonly string[] | undefined, scopes2: rea interface CommonResponse { status: number; statusText: string; - json(): Promise; + json(): Promise; text(): Promise; } diff --git a/src/vs/base/common/observableInternal/debugLocation.ts b/src/vs/base/common/observableInternal/debugLocation.ts index 43da5b908a2..a0e0d07676f 100644 --- a/src/vs/base/common/observableInternal/debugLocation.ts +++ b/src/vs/base/common/observableInternal/debugLocation.ts @@ -16,8 +16,7 @@ export namespace DebugLocation { if (!enabled) { return undefined; } - // eslint-disable-next-line local/code-no-any-casts - const Err = Error as any as { stackTraceLimit: number }; // For the monaco editor checks, which don't have the nodejs types. + const Err = Error as ErrorConstructor & { stackTraceLimit: number }; const l = Err.stackTraceLimit; Err.stackTraceLimit = 3; diff --git a/src/vs/base/common/observableInternal/debugName.ts b/src/vs/base/common/observableInternal/debugName.ts index d5174f75ab4..a6ce5b71450 100644 --- a/src/vs/base/common/observableInternal/debugName.ts +++ b/src/vs/base/common/observableInternal/debugName.ts @@ -103,8 +103,7 @@ function computeDebugName(self: object, data: DebugNameData): string | undefined function findKey(obj: object, value: object): string | undefined { for (const key in obj) { - // eslint-disable-next-line local/code-no-any-casts - if ((obj as any)[key] === value) { + if ((obj as Record)[key] === value) { return key; } } diff --git a/src/vs/base/common/observableInternal/map.ts b/src/vs/base/common/observableInternal/map.ts index 1db8c9ebb26..5cd028db280 100644 --- a/src/vs/base/common/observableInternal/map.ts +++ b/src/vs/base/common/observableInternal/map.ts @@ -51,7 +51,7 @@ export class ObservableMap implements Map { } } - forEach(callbackfn: (value: V, key: K, map: Map) => void, thisArg?: any): void { + forEach(callbackfn: (value: V, key: K, map: Map) => void, thisArg?: unknown): void { this._data.forEach((value, key, _map) => { callbackfn.call(thisArg, value, key, this); }); diff --git a/src/vs/base/common/resourceTree.ts b/src/vs/base/common/resourceTree.ts index c1a1c951bb2..5328c30b448 100644 --- a/src/vs/base/common/resourceTree.ts +++ b/src/vs/base/common/resourceTree.ts @@ -75,7 +75,7 @@ function collect(node: IResourceNode, result: T[]): T[] { return result; } -export class ResourceTree, C> { +export class ResourceTree, C> { readonly root: Node; diff --git a/src/vs/base/common/strings.ts b/src/vs/base/common/strings.ts index 3d60229f8fa..c341d98e26a 100644 --- a/src/vs/base/common/strings.ts +++ b/src/vs/base/common/strings.ts @@ -23,6 +23,7 @@ const _formatRegexp = /{(\d+)}/g; * @param value string to which formatting is applied * @param args replacements for {n}-entries */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any export function format(value: string, ...args: any[]): string { if (args.length === 0) { return value; @@ -322,7 +323,7 @@ export function getIndentationLength(str: string): number { * Function that works identically to String.prototype.replace, except, the * replace function is allowed to be async and return a Promise. */ -export function replaceAsync(str: string, search: RegExp, replacer: (match: string, ...args: any[]) => Promise): Promise { +export function replaceAsync(str: string, search: RegExp, replacer: (match: string, ...args: unknown[]) => Promise): Promise { const parts: (string | Promise)[] = []; let last = 0; diff --git a/src/vs/base/common/uriIpc.ts b/src/vs/base/common/uriIpc.ts index 2022176c1f3..67bf4c3428c 100644 --- a/src/vs/base/common/uriIpc.ts +++ b/src/vs/base/common/uriIpc.ts @@ -30,8 +30,7 @@ export interface IRawURITransformer { } function toJSON(uri: URI): UriComponents { - // eslint-disable-next-line local/code-no-any-casts - return uri.toJSON(); + return uri.toJSON(); } export class URITransformer implements IURITransformer { diff --git a/src/vs/base/node/osDisplayProtocolInfo.ts b/src/vs/base/node/osDisplayProtocolInfo.ts index 2dbc302e02a..41ed6b7eb0a 100644 --- a/src/vs/base/node/osDisplayProtocolInfo.ts +++ b/src/vs/base/node/osDisplayProtocolInfo.ts @@ -18,7 +18,7 @@ const enum DisplayProtocolType { Unknown = 'unknown' } -export async function getDisplayProtocol(errorLogger: (error: any) => void): Promise { +export async function getDisplayProtocol(errorLogger: (error: string | Error) => void): Promise { const xdgSessionType = env[XDG_SESSION_TYPE]; if (xdgSessionType) { diff --git a/src/vs/base/node/osReleaseInfo.ts b/src/vs/base/node/osReleaseInfo.ts index 8c34493531f..890bc254e16 100644 --- a/src/vs/base/node/osReleaseInfo.ts +++ b/src/vs/base/node/osReleaseInfo.ts @@ -13,7 +13,7 @@ type ReleaseInfo = { version_id?: string; }; -export async function getOSReleaseInfo(errorLogger: (error: any) => void): Promise { +export async function getOSReleaseInfo(errorLogger: (error: string | Error) => void): Promise { if (Platform.isMacintosh || Platform.isWindows) { return; } diff --git a/src/vs/platform/accessibility/browser/accessibleView.ts b/src/vs/platform/accessibility/browser/accessibleView.ts index 2846d16bd94..8d174557b14 100644 --- a/src/vs/platform/accessibility/browser/accessibleView.ts +++ b/src/vs/platform/accessibility/browser/accessibleView.ts @@ -171,8 +171,17 @@ export class AccessibleContentProvider extends Disposable implements IAccessible } } -export function isIAccessibleViewContentProvider(obj: any): obj is IAccessibleViewContentProvider { - return obj && obj.id && obj.options && obj.provideContent && obj.onClose && obj.verbositySettingKey; +export function isIAccessibleViewContentProvider(obj: unknown): obj is IAccessibleViewContentProvider { + if (!obj || typeof obj !== 'object') { + return false; + } + + const candidate = obj as Partial; + return !!candidate.id + && !!candidate.options + && typeof candidate.provideContent === 'function' + && typeof candidate.onClose === 'function' + && typeof candidate.verbositySettingKey === 'string'; } export class ExtensionContentProvider extends Disposable implements IBasicContentProvider { diff --git a/src/vs/platform/accessibility/common/accessibility.ts b/src/vs/platform/accessibility/common/accessibility.ts index d12fb600dd5..1757eb84e02 100644 --- a/src/vs/platform/accessibility/common/accessibility.ts +++ b/src/vs/platform/accessibility/common/accessibility.ts @@ -42,10 +42,14 @@ export interface IAccessibilityInformation { role?: string; } -export function isAccessibilityInformation(obj: any): obj is IAccessibilityInformation { - return obj && typeof obj === 'object' - && typeof obj.label === 'string' - && (typeof obj.role === 'undefined' || typeof obj.role === 'string'); +export function isAccessibilityInformation(obj: unknown): obj is IAccessibilityInformation { + if (!obj || typeof obj !== 'object') { + return false; + } + + const candidate = obj as Partial; + return typeof candidate.label === 'string' + && (typeof candidate.role === 'undefined' || typeof candidate.role === 'string'); } export const ACCESSIBLE_VIEW_SHOWN_STORAGE_PREFIX = 'ACCESSIBLE_VIEW_SHOWN_'; diff --git a/src/vs/platform/policy/node/nativePolicyService.ts b/src/vs/platform/policy/node/nativePolicyService.ts index 21bb9c4dbb9..5b08cd99480 100644 --- a/src/vs/platform/policy/node/nativePolicyService.ts +++ b/src/vs/platform/policy/node/nativePolicyService.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { AbstractPolicyService, IPolicyService, PolicyDefinition } from '../common/policy.js'; +import { AbstractPolicyService, IPolicyService, PolicyDefinition, PolicyValue } from '../common/policy.js'; import { IStringDictionary } from '../../../base/common/collections.js'; import { Throttler } from '../../../base/common/async.js'; import type { PolicyUpdate, Watcher } from '@vscode/policy-watcher'; @@ -43,9 +43,8 @@ export class NativePolicyService extends AbstractPolicyService implements IPolic private _onDidPolicyChange(update: PolicyUpdate>): void { this.logService.trace(`NativePolicyService#_onDidPolicyChange - Updated policy values: ${JSON.stringify(update)}`); - for (const key in update) { - // eslint-disable-next-line local/code-no-any-casts - const value = update[key] as any; + for (const key in update as Record) { + const value = update[key]; if (value === undefined) { this.policies.delete(key); diff --git a/src/vs/platform/remote/common/electronRemoteResources.ts b/src/vs/platform/remote/common/electronRemoteResources.ts index e8e0fa86892..1f2dced2752 100644 --- a/src/vs/platform/remote/common/electronRemoteResources.ts +++ b/src/vs/platform/remote/common/electronRemoteResources.ts @@ -13,12 +13,12 @@ export const NODE_REMOTE_RESOURCE_CHANNEL_NAME = 'remoteResourceHandler'; export type NodeRemoteResourceResponse = { body: /* base64 */ string; mimeType?: string; statusCode: number }; export class NodeRemoteResourceRouter implements IClientRouter { - async routeCall(hub: IConnectionHub, command: string, arg?: any): Promise> { + async routeCall(hub: IConnectionHub, command: string, arg?: unknown): Promise> { if (command !== NODE_REMOTE_RESOURCE_IPC_METHOD_NAME) { throw new Error(`Call not found: ${command}`); } - const uri = arg[0] as (UriComponents | undefined); + const uri = Array.isArray(arg) ? arg[0] as (UriComponents | undefined) : undefined; if (uri?.authority) { const connection = hub.connections.find(c => c.ctx === uri.authority); if (connection) { diff --git a/src/vs/platform/remote/common/managedSocket.ts b/src/vs/platform/remote/common/managedSocket.ts index d5d6ba7516d..172508f4c1c 100644 --- a/src/vs/platform/remote/common/managedSocket.ts +++ b/src/vs/platform/remote/common/managedSocket.ts @@ -130,7 +130,7 @@ export abstract class ManagedSocket extends Disposable implements ISocket { public abstract write(buffer: VSBuffer): void; protected abstract closeRemote(): void; - traceSocketEvent(type: SocketDiagnosticsEventType, data?: any): void { + traceSocketEvent(type: SocketDiagnosticsEventType, data?: VSBuffer | Uint8Array | ArrayBuffer | ArrayBufferView | unknown): void { SocketDiagnostics.traceSocketEvent(this, this.debugLabel, type, data); }