UNPKG

refakts

Version:

TypeScript refactoring tool built for AI coding agents to perform precise refactoring operations via command line instead of requiring complete code regeneration.

57 lines 2.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.complexityCheck = void 0; const child_process_1 = require("child_process"); const util_1 = require("util"); const execAsync = (0, util_1.promisify)(child_process_1.exec); exports.complexityCheck = { name: 'complexity', check: async () => { try { const { stdout } = await execAsync('npx complexity-report --format json src'); return analyzeComplexityReport(stdout); } catch { return []; } }, getGroupDefinition: (groupKey) => groupKey === 'complexity' ? { title: 'HIGH COMPLEXITY', description: 'Complex functions are harder to understand, test, and maintain.', actionGuidance: 'Break down complex functions into smaller, single-purpose methods.' } : undefined }; const analyzeComplexityReport = (stdout) => { const report = JSON.parse(stdout); const issues = findComplexityIssues(report); return createComplexityIssues(issues); }; const findComplexityIssues = (report) => { const issues = { hasComplexFunctions: false, hasManyParams: false }; for (const file of report.reports || []) { for (const func of file.functions || []) { if (func.complexity?.cyclomatic && func.complexity.cyclomatic > 5) issues.hasComplexFunctions = true; if (func.params > 2) issues.hasManyParams = true; } } return issues; }; const createComplexityIssues = (issues) => { const result = []; if (issues.hasComplexFunctions) { result.push({ type: 'complexity', message: 'High cyclomatic complexity detected. Break down complex functions into smaller, single-purpose methods.' }); } if (issues.hasManyParams) { result.push({ type: 'complexity', message: 'Functions with more than 2 parameters detected. Consider using parameter objects to group related parameters.' }); } return result; }; //# sourceMappingURL=complexity-check.js.map