diff --git a/eslint-suppressions.json b/eslint-suppressions.json index 49a28c0feeb..b28e647e003 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -2033,11 +2033,6 @@ "count": 3 } }, - "packages/utils/src/errors.ts": { - "no-restricted-syntax": { - "count": 3 - } - }, "packages/utils/src/fs.test.ts": { "@typescript-eslint/no-explicit-any": { "count": 20 @@ -2053,11 +2048,6 @@ "count": 9 } }, - "packages/utils/src/hashing.ts": { - "no-restricted-syntax": { - "count": 3 - } - }, "packages/utils/src/json.ts": { "@typescript-eslint/no-explicit-any": { "count": 1 diff --git a/packages/utils/src/errors.ts b/packages/utils/src/errors.ts index b1df41f1e81..e1dda46de66 100644 --- a/packages/utils/src/errors.ts +++ b/packages/utils/src/errors.ts @@ -26,6 +26,7 @@ function isError(error: unknown): error is Error { * @returns A boolean. */ export function isErrorWithCode(error: unknown): error is { code: string } { + // eslint-disable-next-line no-restricted-syntax -- `in` is deliberate: error classes commonly define `code` on their prototype, which an own-property check such as `hasProperty` would miss. return typeof error === 'object' && error !== null && 'code' in error; } @@ -39,6 +40,7 @@ export function isErrorWithCode(error: unknown): error is { code: string } { export function isErrorWithMessage( error: unknown, ): error is { message: string } { + // eslint-disable-next-line no-restricted-syntax -- `in` is deliberate: `message` lives on `Error.prototype` when an error is constructed without one, so an own-property check such as `hasProperty` would reject real errors. return typeof error === 'object' && error !== null && 'message' in error; } @@ -50,6 +52,7 @@ export function isErrorWithMessage( * @returns A boolean. */ export function isErrorWithStack(error: unknown): error is { stack: string } { + // eslint-disable-next-line no-restricted-syntax -- `in` is deliberate: `stack` may be inherited rather than an own property, so an own-property check such as `hasProperty` would reject real errors. return typeof error === 'object' && error !== null && 'stack' in error; } diff --git a/packages/utils/src/hashing.ts b/packages/utils/src/hashing.ts index d010c7afff7..a12e62ea6e9 100644 --- a/packages/utils/src/hashing.ts +++ b/packages/utils/src/hashing.ts @@ -34,7 +34,6 @@ function isArrayBufferBacked( export async function sha256(bytes: Uint8Array): Promise { // Use crypto.subtle.digest whenever possible as it is faster. if ( - 'crypto' in globalThis && typeof globalThis.crypto === 'object' && globalThis.crypto.subtle?.digest && isArrayBufferBacked(bytes) @@ -57,7 +56,6 @@ export async function sha256(bytes: Uint8Array): Promise { export async function sha512(bytes: Uint8Array): Promise { // Use crypto.subtle.digest whenever possible as it is faster. if ( - 'crypto' in globalThis && typeof globalThis.crypto === 'object' && globalThis.crypto.subtle?.digest && isArrayBufferBacked(bytes) @@ -80,7 +78,6 @@ export async function sha512(bytes: Uint8Array): Promise { export async function sha384(bytes: Uint8Array): Promise { // Use crypto.subtle.digest whenever possible as it is faster. if ( - 'crypto' in globalThis && typeof globalThis.crypto === 'object' && globalThis.crypto.subtle?.digest && isArrayBufferBacked(bytes)