UNPKG

agentsqripts

Version:

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

29 lines (25 loc) 949 B
/** * @file Analyze individual function complexity * @description Single responsibility: Analyze complexity of a single function node */ /** * Analyze individual function complexity */ function analyzeFunctionComplexity(node, lines, filePath) { const startLine = node.loc ? node.loc.start.line : 1; const endLine = node.loc ? node.loc.end.line : lines.length; const funcContent = lines.slice(startLine - 1, endLine).join('\n'); // Count nested loops within function const loopCount = (funcContent.match(/for\s*\(|\.forEach\s*\(|\.map\s*\(|while\s*\(/g) || []).length; const hasNestedLoops = /for.*{[^}]*for|forEach.*{[^}]*forEach/.test(funcContent); return { name: node.id ? node.id.name : 'anonymous', startLine, endLine, complexity: hasNestedLoops ? 'O(n²)' : loopCount > 0 ? 'O(n)' : 'O(1)', loopCount, hasNestedLoops, content: funcContent }; } module.exports = analyzeFunctionComplexity;