Disallow unsafe type assertions (#18688)

This commit is contained in:
Christian Gunderman
2026-02-10 00:10:15 +00:00
committed by GitHub
parent bce1caefd0
commit fd65416a2f
188 changed files with 592 additions and 47 deletions
+4
View File
@@ -203,6 +203,7 @@ export function escapeAnsiCtrlCodes<T>(obj: T): T {
}
regex.lastIndex = 0; // needed for global regex
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return obj.replace(regex, (match) =>
JSON.stringify(match).slice(1, -1),
) as T;
@@ -225,6 +226,7 @@ export function escapeAnsiCtrlCodes<T>(obj: T): T {
newArr[i] = escapedValue;
}
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return (newArr !== null ? newArr : obj) as T;
}
@@ -232,6 +234,7 @@ export function escapeAnsiCtrlCodes<T>(obj: T): T {
const keys = Object.keys(obj);
for (const key of keys) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const value = (obj as Record<string, unknown>)[key];
const escapedValue = escapeAnsiCtrlCodes(value);
@@ -239,6 +242,7 @@ export function escapeAnsiCtrlCodes<T>(obj: T): T {
if (newObj === null) {
newObj = { ...obj };
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
(newObj as Record<string, unknown>)[key] = escapedValue;
}
}