Disallow redundant typecasts. (#15030)

This commit is contained in:
Christian Gunderman
2025-12-12 17:43:43 -08:00
committed by GitHub
parent fcc3b2b5ec
commit 942bcfc61e
86 changed files with 235 additions and 371 deletions
+1 -1
View File
@@ -60,7 +60,7 @@ vi.mock('fs', async (importOriginal) => {
if (mockPaths.has(p.toString())) {
return { isDirectory: () => true } as unknown as import('fs').Stats;
}
return (actualFs as typeof import('fs')).statSync(p as unknown as string);
return actualFs.statSync(p as unknown as string);
}),
realpathSync: vi.fn((p) => p),
};
+2 -2
View File
@@ -123,7 +123,7 @@ export class ExtensionManager extends ExtensionLoader {
'Extensions not yet loaded, must call `loadExtensions` first',
);
}
return this.loadedExtensions!;
return this.loadedExtensions;
}
async installOrUpdateExtension(
@@ -319,7 +319,7 @@ export class ExtensionManager extends ExtensionLoader {
// TODO: Gracefully handle this call failing, we should back up the old
// extension prior to overwriting it and then restore and restart it.
extension = await this.loadExtension(destinationPath)!;
extension = await this.loadExtension(destinationPath);
if (!extension) {
throw new Error(`Extension not found`);
}
@@ -31,7 +31,7 @@ export async function fetchJson<T>(
if (!res.headers.location) {
return reject(new Error('No location header in redirect response'));
}
fetchJson<T>(res.headers.location!, redirectCount++)
fetchJson<T>(res.headers.location, redirectCount++)
.then(resolve)
.catch(reject);
return;
@@ -18,7 +18,7 @@ function buildZodSchemaFromJsonSchema(def: any): z.ZodTypeAny {
if (def.anyOf) {
return z.union(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
def.anyOf.map((d: any) => buildZodSchemaFromJsonSchema(d)) as any,
def.anyOf.map((d: any) => buildZodSchemaFromJsonSchema(d)),
);
}
+15 -19
View File
@@ -2231,7 +2231,7 @@ describe('Settings Loading and Merging', () => {
beforeEach(() => {
vi.resetAllMocks();
mockFsExistsSync = vi.mocked(fs.existsSync);
(mockFsExistsSync as Mock).mockReturnValue(true);
mockFsExistsSync.mockReturnValue(true);
mockFsReadFileSync = vi.mocked(fs.readFileSync);
mockFsReadFileSync.mockReturnValue('{}');
vi.mocked(isWorkspaceTrusted).mockReturnValue({
@@ -2256,15 +2256,13 @@ describe('Settings Loading and Merging', () => {
},
};
(mockFsReadFileSync as Mock).mockImplementation(
(p: fs.PathOrFileDescriptor) => {
if (p === USER_SETTINGS_PATH)
return JSON.stringify(userSettingsContent);
if (p === MOCK_WORKSPACE_SETTINGS_PATH)
return JSON.stringify(workspaceSettingsContent);
return '{}';
},
);
mockFsReadFileSync.mockImplementation((p: fs.PathOrFileDescriptor) => {
if (p === USER_SETTINGS_PATH)
return JSON.stringify(userSettingsContent);
if (p === MOCK_WORKSPACE_SETTINGS_PATH)
return JSON.stringify(workspaceSettingsContent);
return '{}';
});
const loadedSettings = loadSettings(MOCK_WORKSPACE_DIR);
const setValueSpy = vi.spyOn(loadedSettings, 'setValue');
@@ -2329,15 +2327,13 @@ describe('Settings Loading and Merging', () => {
someOtherSetting: 'value',
};
(mockFsReadFileSync as Mock).mockImplementation(
(p: fs.PathOrFileDescriptor) => {
if (p === USER_SETTINGS_PATH)
return JSON.stringify(userSettingsContent);
if (p === MOCK_WORKSPACE_SETTINGS_PATH)
return JSON.stringify(workspaceSettingsContent);
return '{}';
},
);
mockFsReadFileSync.mockImplementation((p: fs.PathOrFileDescriptor) => {
if (p === USER_SETTINGS_PATH)
return JSON.stringify(userSettingsContent);
if (p === MOCK_WORKSPACE_SETTINGS_PATH)
return JSON.stringify(workspaceSettingsContent);
return '{}';
});
const loadedSettings = loadSettings(MOCK_WORKSPACE_DIR);
const setValueSpy = vi.spyOn(loadedSettings, 'setValue');
@@ -33,7 +33,7 @@ describe('SettingsSchema', () => {
];
expectedSettings.forEach((setting) => {
expect(getSettingsSchema()[setting as keyof Settings]).toBeDefined();
expect(getSettingsSchema()[setting]).toBeDefined();
});
});
@@ -66,9 +66,7 @@ describe('SettingsSchema', () => {
];
nestedSettings.forEach((setting) => {
const definition = getSettingsSchema()[
setting as keyof Settings
] as SettingDefinition;
const definition = getSettingsSchema()[setting] as SettingDefinition;
expect(definition.type).toBe('object');
expect(definition.properties).toBeDefined();
expect(typeof definition.properties).toBe('object');
@@ -142,7 +140,7 @@ describe('SettingsSchema', () => {
it('should have consistent default values for boolean settings', () => {
const checkBooleanDefaults = (schema: SettingsSchema) => {
Object.entries(schema).forEach(([, definition]) => {
const def = definition as SettingDefinition;
const def = definition;
if (def.type === 'boolean') {
// Boolean settings can have boolean or undefined defaults (for optional settings)
expect(['boolean', 'undefined']).toContain(typeof def.default);