Disallow unsafe returns. (#19767)

This commit is contained in:
Christian Gunderman
2026-02-21 01:12:56 +00:00
committed by GitHub
parent 09218572d0
commit dfd7721e69
26 changed files with 42 additions and 7 deletions

View File

@@ -147,7 +147,7 @@ function resolveEnvVarsInObject<T>(obj: T): T {
}
if (Array.isArray(obj)) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion, @typescript-eslint/no-unsafe-return
return obj.map((item) => resolveEnvVarsInObject(item)) as unknown as T;
}

View File

@@ -47,6 +47,7 @@ const defaultRequestConfirmation: RequestConfirmationCallback = async (
message,
initial: false,
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return response.confirm;
};

View File

@@ -83,6 +83,7 @@ export class ExtensionRegistryClient {
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const results = await fzf.find(query);
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return results.map((r: { item: RegistryExtension }) => r.item);
}

View File

@@ -179,6 +179,7 @@ export class ExtensionEnablementManager {
readConfig(): AllExtensionsEnablementConfig {
try {
const content = fs.readFileSync(this.configFilePath, 'utf-8');
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return JSON.parse(content);
} catch (error) {
if (

View File

@@ -156,6 +156,7 @@ export async function promptForSetting(
name: 'value',
message: `${setting.name}\n${setting.description}`,
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return response.value;
}

View File

@@ -58,6 +58,7 @@ export function recursivelyHydrateStrings<T>(
if (Array.isArray(obj)) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return obj.map((item) =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
recursivelyHydrateStrings(item, values),
) as unknown as T;
}

View File

@@ -121,5 +121,6 @@ export const createMockCommandContext = (
return output;
};
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return merge(defaultMocks, overrides);
};

View File

@@ -170,6 +170,7 @@ async function searchResourceCandidates(
const results = await fzf.find(normalizedPattern, {
limit: MAX_SUGGESTIONS_TO_SHOW * 3,
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return results.map(
(result: { item: ResourceSuggestionCandidate }) => result.item.suggestion,
);
@@ -193,6 +194,7 @@ async function searchAgentCandidates(
const results = await fzf.find(normalizedPattern, {
limit: MAX_SUGGESTIONS_TO_SHOW,
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return results.map((r: { item: Suggestion }) => r.item);
}

View File

@@ -193,7 +193,11 @@ export const TableRenderer: React.FC<TableRendererProps> = ({
const wrappedRows = styledRows.map((row) => wrapAndProcessRow(row));
// Use the TIGHTEST widths that fit the wrapped content + padding
const adjustedWidths = actualColumnWidths.map((w) => w + COLUMN_PADDING);
const adjustedWidths = actualColumnWidths.map(
(w) =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
w + COLUMN_PADDING,
);
return { wrappedHeaders, wrappedRows, adjustedWidths };
}, [styledHeaders, styledRows, terminalWidth]);

View File

@@ -472,7 +472,7 @@ export class ActivityLogger extends EventEmitter {
body,
pending: true,
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-type-assertion
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-type-assertion, @typescript-eslint/no-unsafe-return
return (oldEnd as any).apply(this, [chunk, ...etc]);
};

View File

@@ -98,6 +98,7 @@ function resolveEnvVarsInObjectInternal<T>(
visited.add(obj);
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const result = obj.map((item) =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
resolveEnvVarsInObjectInternal(item, visited, customEnv),
) as unknown as T;
visited.delete(obj);

View File

@@ -83,6 +83,7 @@ export const getLatestGitHubRelease = async (
if (!releaseTag) {
throw new Error(`Response did not include tag_name field`);
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return releaseTag;
} catch (_error) {
debugLogger.debug(

View File

@@ -40,6 +40,7 @@ export function tryParseJSON(input: string): object | null {
if (!Array.isArray(parsed) && Object.keys(parsed).length === 0) return null;
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return parsed;
} catch (_err) {
return null;

View File

@@ -374,6 +374,7 @@ export function setPendingSettingValue(
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const newSettings = JSON.parse(JSON.stringify(pendingSettings));
setNestedValue(newSettings, path, value);
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return newSettings;
}

View File

@@ -29,6 +29,7 @@ export class AcpFileSystemService implements FileSystemService {
sessionId: this.sessionId,
});
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return response.content;
}

View File

@@ -636,6 +636,7 @@ async function fetchCachedCredentials(): Promise<
for (const keyFile of pathsToTry) {
try {
const keyFileString = await fs.readFile(keyFile, 'utf-8');
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return JSON.parse(keyFileString);
} catch (error) {
// Log specific error for debugging, but continue trying other paths

View File

@@ -59,6 +59,7 @@ export class ProjectRegistry {
try {
const content = await fs.promises.readFile(this.registryPath, 'utf8');
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return JSON.parse(content);
} catch (e) {
debugLogger.debug('Failed to load registry: ', e);

View File

@@ -13,21 +13,19 @@ import type {
GenerateContentConfig,
} from '@google/genai';
import type { Config } from '../config/config.js';
import type { ContentGenerator } from './contentGenerator.js';
import type { AuthType } from './contentGenerator.js';
import type { ContentGenerator, AuthType } from './contentGenerator.js';
import { handleFallback } from '../fallback/handler.js';
import { getResponseText } from '../utils/partUtils.js';
import { reportError } from '../utils/errorReporting.js';
import { getErrorMessage } from '../utils/errors.js';
import { logMalformedJsonResponse } from '../telemetry/loggers.js';
import { MalformedJsonResponseEvent } from '../telemetry/types.js';
import { MalformedJsonResponseEvent, LlmRole } from '../telemetry/types.js';
import { retryWithBackoff } from '../utils/retry.js';
import type { ModelConfigKey } from '../services/modelConfigService.js';
import {
applyModelSelection,
createAvailabilityContextProvider,
} from '../availability/policyHelpers.js';
import { LlmRole } from '../telemetry/types.js';
const DEFAULT_MAX_ATTEMPTS = 5;
@@ -164,6 +162,7 @@ export class BaseLlmClient {
);
// If we are here, the content is valid (not empty and parsable).
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return JSON.parse(
this.cleanJsonResponse(getResponseText(result)!.trim(), model),
);

View File

@@ -83,6 +83,7 @@ export class FakeContentGenerator implements ContentGenerator {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
role: LlmRole,
): Promise<GenerateContentResponse> {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return Object.setPrototypeOf(
this.getNextResponse('generateContent', request),
GenerateContentResponse.prototype,
@@ -116,6 +117,7 @@ export class FakeContentGenerator implements ContentGenerator {
async embedContent(
request: EmbedContentParameters,
): Promise<EmbedContentResponse> {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return Object.setPrototypeOf(
this.getNextResponse('embedContent', request),
EmbedContentResponse.prototype,

View File

@@ -348,6 +348,7 @@ export class IdeClient {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const parsedJson = JSON.parse(textPart.text);
if (parsedJson && typeof parsedJson.content === 'string') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return parsedJson.content;
}
if (parsedJson && parsedJson.content === null) {

View File

@@ -123,6 +123,7 @@ export async function getConnectionConfigFromFile(
`gemini-ide-server-${pid}.json`,
);
const portFileContents = await fs.promises.readFile(portFile, 'utf8');
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return JSON.parse(portFileContents);
} catch (_) {
// For newer extension versions, the file name matches the pattern
@@ -167,6 +168,7 @@ export async function getConnectionConfigFromFile(
}
const parsedContents = fileContents.map((content) => {
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return JSON.parse(content);
} catch (e) {
logger.debug('Failed to parse JSON from config file: ', e);
@@ -196,6 +198,7 @@ export async function getConnectionConfigFromFile(
if (fileIndex !== -1) {
logger.debug(`Selected IDE connection file: ${matchingFiles[fileIndex]}`);
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return selected;
}
@@ -213,6 +216,7 @@ export async function getConnectionConfigFromFile(
`Selected IDE connection file (matched port from env): ${matchingFiles[fileIndex]}`,
);
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return selected;
}
}
@@ -225,6 +229,7 @@ export async function getConnectionConfigFromFile(
`Selected first valid IDE connection file: ${matchingFiles[fileIndex]}`,
);
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return selected;
}

View File

@@ -419,6 +419,7 @@ export class ChatRecordingService {
private readConversation(): ConversationRecord {
try {
this.cachedLastConvData = fs.readFileSync(this.conversationFile!, 'utf8');
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return JSON.parse(this.cachedLastConvData);
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion

View File

@@ -149,6 +149,7 @@ class RecursiveFileSearch implements FileSearch {
filteredCandidates = await this.fzf
.find(pattern)
.then((results: Array<FzfResultItem<string>>) =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
results.map((entry: FzfResultItem<string>) => entry.item),
)
.catch(() => {

View File

@@ -27,6 +27,7 @@ export function safeJsonStringify(
}
seen.add(value);
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return value;
},
space,
@@ -60,6 +61,7 @@ export function safeJsonStringifyBooleanValuesOnly(obj: any): string {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
if ((value as Config) !== null && !configSeen) {
configSeen = true;
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return value;
}
if (typeof value === 'boolean') {

View File

@@ -91,8 +91,10 @@ export function createWorkingStdio() {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const value = Reflect.get(target, prop, receiver);
if (typeof value === 'function') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return value.bind(target);
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return value;
},
});
@@ -105,8 +107,10 @@ export function createWorkingStdio() {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const value = Reflect.get(target, prop, receiver);
if (typeof value === 'function') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return value.bind(target);
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return value;
},
});