UNPKG

agentsqripts

Version:

Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems

108 lines (99 loc) 4.26 kB
/** * @file Code cleanup opportunity analyzer with comprehensive maintenance pattern detection * @description Single responsibility: Coordinate multiple cleanup detectors for thorough maintenance analysis * * This core analyzer orchestrates multiple specialized cleanup detectors to identify * comprehensive code maintenance opportunities including dead code, barrel files, * orphaned comments, and intra-file duplication. It provides prioritized recommendations * for improving codebase hygiene and reducing technical debt. * * Design rationale: * - Multi-detector approach provides comprehensive cleanup opportunity identification * - Scoring system quantifies cleanup quality for measurable improvement tracking * - Priority calculation guides maintenance effort allocation for maximum impact * - Modular detector architecture enables easy addition of new cleanup pattern detection * - Conservative threshold approach minimizes false positive cleanup recommendations * * Cleanup detection scope: * - Barrel file identification and optimization opportunities * - Dead code detection including unused variables and unreachable code * - Orphaned comment identification for documentation maintenance * - Intra-file duplication patterns requiring refactoring attention * - Priority assessment for focused maintenance effort allocation */ const { isBarrelFile } = require('./barrelDetector'); const { findDeadCode } = require('./deadCodeDetector'); const { findOrphanedComments } = require('./orphanedCommentScanner'); const { findIntraFileDuplication } = require('./duplicationDetector'); const { determinePriority } = require('./priorityCalculator'); /** * Analyze cleanup opportunities in file content * @param {string} filePath - File path * @param {string} content - File content * @returns {Object} Cleanup analysis results */ function analyzeFileContent(filePath, content) { const analysis = { file: filePath, opportunities: [], issues: [], cleanupScore: 100, // 0-100, higher is cleaner priority: 'LOW' // LOW, MEDIUM, HIGH }; // Check for barrel file if (isBarrelFile(content, filePath)) { analysis.opportunities.push({ type: 'barrel_file', severity: 'MEDIUM', description: 'File appears to be a barrel file (only re-exports)', recommendation: 'Consider if this barrel file is necessary or could be simplified', effort: 'LOW' }); analysis.cleanupScore -= 10; } // Find dead code const deadCode = findDeadCode(content); if (deadCode.length > 0) { analysis.opportunities.push({ type: 'dead_code', severity: deadCode.length > 5 ? 'HIGH' : 'MEDIUM', description: `Found ${deadCode.length} instances of potentially dead code`, items: deadCode, recommendation: 'Remove unused variables, functions, and unreachable code', effort: deadCode.length > 10 ? 'HIGH' : 'MEDIUM' }); analysis.cleanupScore -= Math.min(30, deadCode.length * 3); } // Check for orphaned comments const orphanedComments = findOrphanedComments(content); if (orphanedComments.length > 0) { analysis.opportunities.push({ type: 'orphaned_comments', severity: 'LOW', description: `Found ${orphanedComments.length} potentially orphaned comments`, items: orphanedComments, recommendation: 'Review and remove outdated or irrelevant comments', effort: 'LOW' }); analysis.cleanupScore -= Math.min(10, orphanedComments.length * 2); } // Check for code duplication within file const duplication = findIntraFileDuplication(content); if (duplication.score > 0.2) { analysis.opportunities.push({ type: 'code_duplication', severity: duplication.score > 0.4 ? 'HIGH' : 'MEDIUM', description: `Code duplication detected (score: ${duplication.score.toFixed(2)})`, duplicates: duplication.duplicates, recommendation: 'Extract duplicated code into reusable functions', effort: 'MEDIUM' }); analysis.cleanupScore -= Math.round(duplication.score * 20); } // Determine priority analysis.priority = determinePriority(analysis.cleanupScore, analysis.opportunities); return analysis; } module.exports = { analyzeFileContent };