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

@@ -208,6 +208,7 @@ function toContent(content: ContentUnion): Content {
// it's a Part
return {
role: 'user',
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
parts: [toPart(content as Part)],
};
}

View File

@@ -44,6 +44,7 @@ export async function getExperiments(
'Invalid format for experiments file: `flags` and `experimentIds` must be arrays if present.',
);
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return parseExperiments(response as ListExperimentsResponse);
} catch (e) {
debugLogger.debug('Failed to read experiments from GEMINI_EXP', e);

View File

@@ -125,6 +125,7 @@ export class OAuthCredentialStorage {
throw error;
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const credentials = JSON.parse(credsJson) as Credentials;
// Save to new storage

View File

@@ -115,6 +115,7 @@ async function initOauthClient(
if (
credentials &&
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
(credentials as { type?: string }).type ===
'external_account_authorized_user'
) {
@@ -602,6 +603,7 @@ export function getAvailablePort(): Promise<number> {
}
const server = net.createServer();
server.listen(0, () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const address = server.address()! as net.AddressInfo;
port = address.port;
});

View File

@@ -301,6 +301,7 @@ export class CodeAssistServer implements ContentGenerator {
body: JSON.stringify(req),
signal,
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return res.data as T;
}
@@ -318,6 +319,7 @@ export class CodeAssistServer implements ContentGenerator {
responseType: 'json',
signal,
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return res.data as T;
}
@@ -351,6 +353,7 @@ export class CodeAssistServer implements ContentGenerator {
return (async function* (): AsyncGenerator<T> {
const rl = readline.createInterface({
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
input: res.data as NodeJS.ReadableStream,
crlfDelay: Infinity, // Recognizes '\r\n' and '\n' as line breaks
});
@@ -363,6 +366,7 @@ export class CodeAssistServer implements ContentGenerator {
if (bufferedLines.length === 0) {
continue; // no data to yield
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
yield JSON.parse(bufferedLines.join('\n')) as T;
bufferedLines = []; // Reset the buffer after yielding
}
@@ -390,11 +394,13 @@ export class CodeAssistServer implements ContentGenerator {
function isVpcScAffectedUser(error: unknown): boolean {
if (error && typeof error === 'object' && 'response' in error) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const gaxiosError = error as {
response?: {
data?: unknown;
};
};
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const response = gaxiosError.response?.data as
| GoogleRpcResponse
| undefined;