run_linter
Run standardized linting for projects, enabling automatic fixes and targeting specific files to ensure code quality and consistency.
Instructions
Run standardized linter for the project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| files | No | Specific files to lint | |
| fix | No | Attempt to fix issues automatically |
Implementation Reference
- src/tools/runLinter.ts:6-28 (handler)The RunLinterTool class implements the core logic for the run_linter tool. It extends BaseExecTool and provides the action name 'Lint' and builds the lint command based on project config, optional --fix flag, and file list.class RunLinterTool extends BaseExecTool<LinterOptions> { protected getActionName(): string { return 'Lint'; } protected async buildCommand(args: LinterOptions): Promise<string> { const { fix = false, files = [] } = args; const config = await loadProjectConfig(); const command = config.lintCommand ?? 'npm run lint'; const parts = [command]; if (fix && !command.includes('--fix')) { parts.push('--fix'); } if (files.length > 0) { parts.push(...files); } return parts.join(' '); } }
- src/tools/runLinter.ts:32-34 (handler)The exported runLinter function acts as the direct handler entry point, delegating to the tool instance's execute method.export async function runLinter(args: LinterOptions): Promise<CallToolResult> { return tool.execute(args); }
- src/types/index.ts:54-57 (schema)Type definition for the input schema of the run_linter tool, including optional fix flag and list of files to lint.export interface LinterOptions { fix?: boolean; files?: string[]; }
- src/tools/exec-base.ts:9-42 (helper)BaseExecTool provides the generic execution logic for shell commands, used by RunLinterTool.export abstract class BaseExecTool<T = unknown> { protected abstract getActionName(): string; protected abstract buildCommand(args: T): Promise<string> | string; async execute(args: T): Promise<CallToolResult> { try { const command = await this.buildCommand(args); let output = ''; let error = ''; let exitCode = 0; try { const result = await execAsync(command, { cwd: process.cwd(), env: process.env, maxBuffer: 1024 * 1024 * 10, }); output = result.stdout; error = result.stderr; } catch (execError) { const err = execError as { stdout?: string; stderr?: string; message?: string; code?: number }; output = err.stdout ?? ''; error = err.stderr ?? err.message ?? 'Unknown error'; exitCode = err.code ?? 1; } const formattedOutput = formatExecOutput(output, error, exitCode, this.getActionName()); return createSuccessResult(formattedOutput); } catch (error) { return createErrorResult(this.getActionName(), error); } } }