UNPKG

agentsqripts

Version:

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

50 lines (40 loc) 1.48 kB
/** * @file Determine the best refactoring strategy * @description Single responsibility: Analyze pattern and determine refactoring approach */ const detectConfigurationPattern = require('./detectConfigurationPattern'); const detectArrayProcessingPattern = require('./detectArrayProcessingPattern'); const areRelatedFunctions = require('./areRelatedFunctions'); /** * Determine the best refactoring strategy */ function determineRefactoringStrategy(group) { const { blocks, pattern } = group; const firstBlock = blocks[0]; // Exact duplicates of utility functions if (pattern === 'exact_duplicate' && firstBlock.type === 'function') { return 'EXTRACT_UTILITY_FUNCTION'; } // Class methods with similar logic if (blocks.every(b => b.type === 'classMethod')) { return 'EXTRACT_BASE_CLASS'; } // Similar functions with parameter differences if (pattern === 'parameterized_logic' && firstBlock.type === 'function') { return 'PARAMETERIZE_FUNCTION'; } // Configuration or initialization patterns if (detectConfigurationPattern(blocks)) { return 'EXTRACT_CONFIGURATION'; } // Array processing patterns if (detectArrayProcessingPattern(blocks)) { return 'USE_HIGHER_ORDER_FUNCTION'; } // Multiple related functions if (blocks.length > 3 && areRelatedFunctions(blocks)) { return 'EXTRACT_SHARED_MODULE'; } return 'EXTRACT_UTILITY_FUNCTION'; } module.exports = determineRefactoringStrategy;