Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions packages/utils/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down
3 changes: 0 additions & 3 deletions packages/utils/src/hashing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function isArrayBufferBacked(
export async function sha256(bytes: Uint8Array): Promise<Uint8Array> {
// Use crypto.subtle.digest whenever possible as it is faster.
if (
'crypto' in globalThis &&
typeof globalThis.crypto === 'object' &&
globalThis.crypto.subtle?.digest &&
isArrayBufferBacked(bytes)
Expand All @@ -57,7 +56,6 @@ export async function sha256(bytes: Uint8Array): Promise<Uint8Array> {
export async function sha512(bytes: Uint8Array): Promise<Uint8Array> {
// Use crypto.subtle.digest whenever possible as it is faster.
if (
'crypto' in globalThis &&
typeof globalThis.crypto === 'object' &&
globalThis.crypto.subtle?.digest &&
isArrayBufferBacked(bytes)
Expand All @@ -80,7 +78,6 @@ export async function sha512(bytes: Uint8Array): Promise<Uint8Array> {
export async function sha384(bytes: Uint8Array): Promise<Uint8Array> {
// Use crypto.subtle.digest whenever possible as it is faster.
if (
'crypto' in globalThis &&
typeof globalThis.crypto === 'object' &&
globalThis.crypto.subtle?.digest &&
isArrayBufferBacked(bytes)
Expand Down
Loading