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

View File

@@ -147,7 +147,8 @@ export class ActivityLogger extends EventEmitter {
? input
: input instanceof URL
? input.toString()
: (input as any).url;
: // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
(input as any).url;
if (url.includes('127.0.0.1') || url.includes('localhost'))
return originalFetch(input, init);
@@ -311,6 +312,7 @@ export class ActivityLogger extends EventEmitter {
req.write = function (chunk: any, ...etc: any[]) {
if (chunk) {
const encoding =
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
typeof etc[0] === 'string' ? (etc[0] as BufferEncoding) : undefined;
requestChunks.push(
Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding),
@@ -322,6 +324,7 @@ export class ActivityLogger extends EventEmitter {
req.end = function (this: any, chunk: any, ...etc: any[]) {
if (chunk && typeof chunk !== 'function') {
const encoding =
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
typeof etc[0] === 'string' ? (etc[0] as BufferEncoding) : undefined;
requestChunks.push(
Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding),

View File

@@ -29,6 +29,7 @@ export function updateSettingsFilePreservingFormat(
let parsed: Record<string, unknown>;
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
parsed = parse(originalContent) as Record<string, unknown>;
} catch (error) {
coreEvents.emitFeedback(
@@ -61,7 +62,9 @@ function preserveCommentsOnPropertyDeletion(
const beforeSym = Symbol.for(`before:${propName}`);
const afterSym = Symbol.for(`after:${propName}`);
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const beforeComments = target[beforeSym] as unknown[] | undefined;
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const afterComments = target[afterSym] as unknown[] | undefined;
if (!beforeComments && !afterComments) return;
@@ -137,7 +140,9 @@ function applyKeyDiff(
if (isObj && isBaseObj) {
applyKeyDiff(
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
baseVal as Record<string, unknown>,
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
nextVal as Record<string, unknown>,
);
} else if (isArr && isBaseArr) {

View File

@@ -67,6 +67,7 @@ function mergeRecursively(
} else if (isPlainObject(srcValue)) {
target[key] = {};
mergeRecursively(
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
target[key] as MergeableObject,
srcValue,
getMergeStrategyForPath,

View File

@@ -82,6 +82,7 @@ function resolveEnvVarsInObjectInternal<T>(
}
if (typeof obj === 'string') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return resolveEnvVarsInString(obj, customEnv) as unknown as T;
}
@@ -89,10 +90,12 @@ function resolveEnvVarsInObjectInternal<T>(
// Check for circular reference
if (visited.has(obj)) {
// Return a shallow copy to break the cycle
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return [...obj] as unknown as T;
}
visited.add(obj);
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const result = obj.map((item) =>
resolveEnvVarsInObjectInternal(item, visited, customEnv),
) as unknown as T;

View File

@@ -38,6 +38,7 @@ interface ErrorWithCode extends Error {
* Extracts the appropriate error code from an error object.
*/
function extractErrorCode(error: unknown): string | number {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const errorWithCode = error as ErrorWithCode;
// Prioritize exitCode for FatalError types, fall back to other codes

View File

@@ -273,6 +273,7 @@ function parseRetentionPeriod(period: string): number {
);
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return value * MULTIPLIERS[unit as keyof typeof MULTIPLIERS];
}
@@ -293,6 +294,7 @@ function validateRetentionConfig(
try {
maxAgeMs = parseRetentionPeriod(retentionConfig.maxAge);
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return (error as Error | string).toString();
}

View File

@@ -617,7 +617,8 @@ export function convertSessionToHistoryFormats(
clientHistory.push({
role: 'user',
parts: Array.isArray(msg.content)
? (msg.content as Part[])
? // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
(msg.content as Part[])
: [{ text: contentString }],
});
} else if (msg.type === 'gemini') {
@@ -670,6 +671,7 @@ export function convertSessionToHistoryFormats(
} else if (Array.isArray(toolCall.result)) {
// toolCall.result is an array containing properly formatted
// function responses
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
functionResponseParts.push(...(toolCall.result as Part[]));
continue;
} else {

View File

@@ -145,6 +145,7 @@ export function getNestedValue(
return value;
}
if (value && typeof value === 'object' && value !== null) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return getNestedValue(value as Record<string, unknown>, rest);
}
return undefined;
@@ -169,12 +170,14 @@ export function getEffectiveValue(
// Check the current scope's settings first
let value = getNestedValue(settings as Record<string, unknown>, path);
if (value !== undefined) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return value as SettingsValue;
}
// Check the merged settings for an inherited value
value = getNestedValue(mergedSettings as Record<string, unknown>, path);
if (value !== undefined) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return value as SettingsValue;
}
@@ -354,6 +357,7 @@ function setNestedValue(
obj[first] = {};
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
setNestedValue(obj[first] as Record<string, unknown>, rest, value);
return obj;
}