UNPKG

agentsqripts

Version:

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

71 lines (62 loc) 2.38 kB
/** * @file DRY/WET score calculation * @description Calculates DRY scores and grades for code analysis */ /** * Calculate WET score for a file based on duplicate groups * @param {Array} duplicateGroups - Groups of duplicate code blocks * @param {number} totalLines - Total lines in the file * @returns {number} WET score (0-100, higher = more duplication) */ function calculateWetScore(duplicateGroups, totalLines) { if (duplicateGroups.length === 0) return 0; const duplicateLines = duplicateGroups.reduce((sum, group) => { return sum + group.blocks.reduce((blockSum, block) => blockSum + block.lines.length, 0); }, 0); // WET score as percentage of duplicate lines (higher = more WET) const wetScore = totalLines > 0 ? (duplicateLines / totalLines) * 100 : 0; // Apply severity multiplier const severityMultiplier = duplicateGroups.reduce((max, group) => { const severity = group.pattern.severity; const multiplier = severity === 'HIGH' ? 1.5 : severity === 'MEDIUM' ? 1.2 : 1.0; return Math.max(max, multiplier); }, 1.0); return Math.min(100, wetScore * severityMultiplier); } /** * Calculate DRY score (inverse of WET score) * @param {Array} duplicateGroups - Groups of duplicate code blocks * @param {number} totalLines - Total lines in the file * @returns {number} DRY score (0-100, higher = better) */ function calculateDryScore(duplicateGroups, totalLines) { const wetScore = calculateWetScore(duplicateGroups, totalLines); return 100 - wetScore; } /** * Convert DRY score to letter grade using standard academic grading * @param {number} dryScore - DRY score (0-100) * @returns {string} Grade letter */ function getDryGrade(dryScore) { if (dryScore >= 90) return 'A'; // Excellent - Minimal duplication if (dryScore >= 80) return 'B'; // Good - Low duplication if (dryScore >= 70) return 'C'; // Average - Some duplication if (dryScore >= 60) return 'D'; // Below Average - Significant duplication return 'F'; // Failing - Major duplication issues } /** * Legacy function for backward compatibility * @deprecated Use getDryGrade with calculateDryScore instead */ function getWetGrade(wetScore) { const dryScore = 100 - wetScore; return getDryGrade(dryScore); } module.exports = { calculateWetScore, calculateDryScore, getDryGrade, getWetGrade };