UNPKG

agentsqripts

Version:

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

33 lines (28 loc) 1.05 kB
/** * @file Group savings calculation * @description Responsible for calculating estimated savings from deduplication */ /** * Calculate estimated savings from deduplication * @param {Object} group - Duplicate group * @param {Object} pattern - WET pattern * @returns {Object} Savings estimates */ function calculateEstimatedSavings(group, pattern) { const totalLines = group.blocks.reduce((sum, block) => sum + block.lines.length, 0); const avgLinesPerBlock = totalLines / group.blocks.length; // Estimate lines that could be reduced // Keep one instance, eliminate the rest, add function overhead const linesReduced = Math.max(0, totalLines - avgLinesPerBlock - 3); // -3 for function overhead // Complexity reduction based on centralization const complexityReduction = Math.round(group.complexityScore * 0.7); // 70% reduction from centralization return { linesReduced, complexityReduction, effort: pattern.effort, impact: pattern.impact }; } module.exports = { calculateEstimatedSavings };