UNPKG

agentsqripts

Version:

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

83 lines (73 loc) 2.56 kB
/** * @file Classify the type of duplication based on multiple factors * @description Single responsibility: Main orchestrator for duplication type classification */ const analyzeDifferencePatterns = require('./analyzeDifferencePatterns'); const isTemplatePattern = require('./isTemplatePattern'); const isAcceptableSimilarity = require('./isAcceptableSimilarity'); /** * Classify the type of duplication based on multiple factors * @param {Array} blocks - Array of duplicate blocks * @param {Object} context - Additional context (file types, frameworks, etc.) * @returns {Object} Classification result */ function classifyDuplicationType(blocks, context = {}) { if (!blocks || blocks.length < 2) { return { type: 'NOT_DUPLICATE', confidence: 1.0 }; } // Check for exact duplicates const firstHash = blocks[0].hash; if (blocks.every(b => b.hash === firstHash)) { return { type: 'EXACT_DUPLICATE', subtype: 'identical_code', confidence: 1.0, recommendation: 'EXTRACT_IMMEDIATELY' }; } // Analyze the nature of differences const classification = analyzeDifferencePatterns(blocks); // Check if it's a template pattern if (isTemplatePattern(blocks, classification)) { return { type: 'TEMPLATE_PATTERN', subtype: classification.pattern, confidence: classification.confidence, recommendation: 'CONSIDER_FRAMEWORK_PATTERNS' }; } // Check if it's acceptable similarity if (isAcceptableSimilarity(blocks, context, classification)) { return { type: 'ACCEPTABLE_SIMILARITY', subtype: classification.reason, confidence: classification.confidence, recommendation: 'NO_ACTION_NEEDED' }; } // Check for parameterizable logic if (classification.parameterizableVariations > 0.7) { return { type: 'PARAMETERIZABLE_DUPLICATE', subtype: 'variable_differences', confidence: classification.confidence, recommendation: 'EXTRACT_WITH_PARAMETERS' }; } // Similar structure but different logic if (classification.structuralSimilarity > 0.8 && classification.logicalSimilarity < 0.5) { return { type: 'STRUCTURAL_SIMILARITY', subtype: 'different_logic', confidence: classification.confidence, recommendation: 'EVALUATE_CASE_BY_CASE' }; } return { type: 'SIMILAR_PATTERN', subtype: 'general_similarity', confidence: classification.confidence, recommendation: 'CONSIDER_REFACTORING' }; } module.exports = classifyDuplicationType;