UNPKG

agentsqripts

Version:

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

34 lines (27 loc) 1.12 kB
/** * @file Normalize content for comparison * @description Single responsibility: Normalize code for semantic comparison by removing variable names and whitespace */ /** * Normalize content for comparison (remove variable names, whitespace, etc.) */ function normalizeForComparison(content, type) { let normalized = content; // Remove comments normalized = normalized.replace(/\/\*[\s\S]*?\*\//g, ''); normalized = normalized.replace(/\/\/.*$/gm, ''); // Normalize whitespace normalized = normalized.replace(/\s+/g, ' ').trim(); // For semantic comparison, replace variable names with placeholders if (type === 'function' || type === 'method' || type === 'classMethod') { // Replace parameter names normalized = normalized.replace(/\(([^)]*)\)/g, (match, params) => { const paramList = params.split(',').map((p, i) => `param${i}`).join(','); return `(${paramList})`; }); // Replace variable declarations normalized = normalized.replace(/\b(const|let|var)\s+(\w+)/g, '$1 VAR'); } return normalized; } module.exports = normalizeForComparison;