agentsqripts
Version:
Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems
29 lines (23 loc) • 918 B
JavaScript
/**
* @file Analyze render method complexity
* @description Single responsibility: Calculate complexity score of React render method
*/
/**
* Analyze render method complexity
*/
function analyzeRenderComplexity(lines, startIndex) {
let complexity = 0;
let braceDepth = 0;
for (let i = startIndex; i < Math.min(lines.length, startIndex + 50); i++) {
const line = lines[i];
braceDepth += (line.match(/{/g) || []).length - (line.match(/}/g) || []).length;
// Add complexity for various patterns
if (/if\s*\(|switch\s*\(|\?.*:/.test(line)) complexity += 2;
if (/map\s*\(|filter\s*\(|reduce\s*\(/.test(line)) complexity += 3;
if (/for\s*\(|while\s*\(/.test(line)) complexity += 4;
if (/async|await|Promise/.test(line)) complexity += 3;
if (braceDepth === 0 && i > startIndex) break;
}
return { score: complexity };
}
module.exports = analyzeRenderComplexity;