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
@@ -14,7 +14,7 @@ import {
type Mock,
} from 'vitest';
import { format } from 'node:util';
import { type CommandModule, type Argv } from 'yargs';
import { type Argv } from 'yargs';
import { handleDisable, disableCommand } from './disable.js';
import { ExtensionManager } from '../../config/extension-manager.js';
import {
@@ -148,7 +148,7 @@ describe('extensions disable command', () => {
});
describe('disableCommand', () => {
const command = disableCommand as CommandModule;
const command = disableCommand;
it('should have correct command and describe', () => {
expect(command.command).toBe('disable [--scope] <name>');
@@ -65,7 +65,7 @@ export const disableCommand: CommandModule = {
argv.scope &&
!Object.values(SettingScope)
.map((s) => s.toLowerCase())
.includes((argv.scope as string).toLowerCase())
.includes(argv.scope.toLowerCase())
) {
throw new Error(
`Invalid scope: ${argv.scope}. Please use one of ${Object.values(
@@ -14,7 +14,7 @@ import {
type Mock,
} from 'vitest';
import { format } from 'node:util';
import { type CommandModule, type Argv } from 'yargs';
import { type Argv } from 'yargs';
import { handleEnable, enableCommand } from './enable.js';
import { ExtensionManager } from '../../config/extension-manager.js';
import {
@@ -137,7 +137,7 @@ describe('extensions enable command', () => {
});
describe('enableCommand', () => {
const command = enableCommand as CommandModule;
const command = enableCommand;
it('should have correct command and describe', () => {
expect(command.command).toBe('enable [--scope] <name>');
@@ -70,7 +70,7 @@ export const enableCommand: CommandModule = {
argv.scope &&
!Object.values(SettingScope)
.map((s) => s.toLowerCase())
.includes((argv.scope as string).toLowerCase())
.includes(argv.scope.toLowerCase())
) {
throw new Error(
`Invalid scope: ${argv.scope}. Please use one of ${Object.values(
@@ -4,15 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
import {
describe,
it,
expect,
vi,
beforeEach,
afterEach,
type Mock,
} from 'vitest';
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { z } from 'zod';
@@ -90,7 +82,7 @@ describe('MCP Server Example', () => {
json: vi.fn().mockResolvedValue(mockPosts),
});
const toolFn = (mockRegisterTool as Mock).mock.calls[0][2];
const toolFn = mockRegisterTool.mock.calls[0][2];
const result = await toolFn();
expect(global.fetch).toHaveBeenCalledWith(
@@ -109,7 +101,7 @@ describe('MCP Server Example', () => {
describe('poem-writer prompt implementation', () => {
it('should generate a prompt with a title', () => {
const promptFn = (mockRegisterPrompt as Mock).mock.calls[0][2];
const promptFn = mockRegisterPrompt.mock.calls[0][2];
const result = promptFn({ title: 'My Poem' });
expect(result).toEqual({
messages: [
@@ -125,7 +117,7 @@ describe('MCP Server Example', () => {
});
it('should generate a prompt with a title and mood', () => {
const promptFn = (mockRegisterPrompt as Mock).mock.calls[0][2];
const promptFn = mockRegisterPrompt.mock.calls[0][2];
const result = promptFn({ title: 'My Poem', mood: 'sad' });
expect(result).toEqual({
messages: [
@@ -14,7 +14,7 @@ import {
type Mock,
} from 'vitest';
import { format } from 'node:util';
import { type CommandModule, type Argv } from 'yargs';
import { type Argv } from 'yargs';
import { handleLink, linkCommand } from './link.js';
import { ExtensionManager } from '../../config/extension-manager.js';
import { loadSettings, type LoadedSettings } from '../../config/settings.js';
@@ -126,7 +126,7 @@ describe('extensions link command', () => {
});
describe('linkCommand', () => {
const command = linkCommand as CommandModule;
const command = linkCommand;
it('should have correct command and describe', () => {
expect(command.command).toBe('link <path>');
@@ -6,7 +6,6 @@
import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest';
import { format } from 'node:util';
import { type CommandModule } from 'yargs';
import { handleList, listCommand } from './list.js';
import { ExtensionManager } from '../../config/extension-manager.js';
import { loadSettings, type LoadedSettings } from '../../config/settings.js';
@@ -124,7 +123,7 @@ describe('extensions list command', () => {
});
describe('listCommand', () => {
const command = listCommand as CommandModule;
const command = listCommand;
it('should have correct command and describe', () => {
expect(command.command).toBe('list');
@@ -14,7 +14,7 @@ import {
type Mock,
} from 'vitest';
import { format } from 'node:util';
import { type CommandModule, type Argv } from 'yargs';
import { type Argv } from 'yargs';
import { handleUninstall, uninstallCommand } from './uninstall.js';
import { ExtensionManager } from '../../config/extension-manager.js';
import { loadSettings, type LoadedSettings } from '../../config/settings.js';
@@ -233,7 +233,7 @@ describe('extensions uninstall command', () => {
});
describe('uninstallCommand', () => {
const command = uninstallCommand as CommandModule;
const command = uninstallCommand;
it('should have correct command and describe', () => {
expect(command.command).toBe('uninstall <names..>');
@@ -62,7 +62,7 @@ export const uninstallCommand: CommandModule = {
array: true,
})
.check((argv) => {
if (!argv.names || (argv.names as string[]).length === 0) {
if (!argv.names || argv.names.length === 0) {
throw new Error(
'Please include at least one extension name to uninstall as a positional argument.',
);
@@ -14,7 +14,7 @@ import {
type Mock,
} from 'vitest';
import { format } from 'node:util';
import { type CommandModule, type Argv } from 'yargs';
import { type Argv } from 'yargs';
import { handleUpdate, updateCommand } from './update.js';
import { ExtensionManager } from '../../config/extension-manager.js';
import { loadSettings, type LoadedSettings } from '../../config/settings.js';
@@ -155,7 +155,7 @@ describe('extensions update command', () => {
});
describe('updateCommand', () => {
const command = updateCommand as CommandModule;
const command = updateCommand;
it('should have correct command and describe', () => {
expect(command.command).toBe('update [<name>] [--all]');