agentsqripts
Version:
Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems
32 lines (26 loc) • 763 B
JavaScript
/**
* @file Code normalization
* @description Normalizes code for WET analysis comparison
*/
/**
* Normalizes code lines for comparison
* @param {string} line - Code line to normalize
* @param {Object} options - Normalization options
* @returns {string} Normalized line
*/
function normalizeLine(line, options = {}) {
const { ignoreComments = true, ignoreWhitespace = true } = options;
let normalized = line;
// Remove comments if requested
if (ignoreComments) {
normalized = normalized.replace(/\/\/.*$/, '').replace(/\/\*.*?\*\//g, '');
}
// Normalize whitespace if requested
if (ignoreWhitespace) {
normalized = normalized.replace(/\s+/g, ' ').trim();
}
return normalized;
}
module.exports = {
normalizeLine
};