suggest_refactoring
Analyzes code files to identify refactoring opportunities that improve maintainability and reduce complexity.
Instructions
Suggest refactoring opportunities based on code analysis
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| files | Yes | File paths to analyze |
Implementation Reference
- src/tools/code-quality.ts:264-287 (handler)The switch case in handleCodeQualityTool that implements the 'suggest_refactoring' tool. It reads the specified files, analyzes their code quality, and returns a list of refactoring suggestions based on detected code smells and duplications.case 'suggest_refactoring': { const files = params.files as string[]; const codeFiles = await FileReader.readFiles(files.join(',')); const metrics = await codeAnalyzer.analyzeCodeQuality(codeFiles); const suggestions = [ ...metrics.codeSmells.map((smell) => ({ type: 'code_smell', location: smell.location, description: smell.description, suggestion: smell.suggestion || 'Consider refactoring', priority: smell.severity === 'critical' || smell.severity === 'high' ? 'high' : 'medium', })), ...metrics.duplications.map((dup) => ({ type: 'duplication', location: dup.firstFile, description: `Duplicate code found with ${dup.secondFile}`, suggestion: 'Extract common code into shared function', priority: 'medium', })), ]; return suggestions; }
- src/tools/code-quality.ts:159-173 (registration)The tool registration object for 'suggest_refactoring' exported in the codeQualityTools array, defining its name, description, and input schema requiring an array of file paths.{ name: 'suggest_refactoring', description: 'Suggest refactoring opportunities based on code analysis', inputSchema: { type: 'object', properties: { files: { type: 'array', items: { type: 'string' }, description: 'File paths to analyze', }, }, required: ['files'], }, },
- src/tools/code-quality.ts:162-171 (schema)The input schema for the 'suggest_refactoring' tool, specifying an object with a required 'files' array of strings.inputSchema: { type: 'object', properties: { files: { type: 'array', items: { type: 'string' }, description: 'File paths to analyze', }, }, required: ['files'],