UNPKG

agentsqripts

Version:

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

51 lines (44 loc) 1.84 kB
/** * @file Detect cross-file complexity patterns * @description Single responsibility: Detect complexity patterns across files */ const extractFunctionCalls = require('./extractFunctionCalls'); const findComplexFunction = require('../resolvers/findComplexFunction'); /** * Detect cross-file complexity patterns */ function detectCrossFileComplexity(content, filePath, fileMap) { const issues = []; const lines = content.split('\n'); // Look for function calls within loops lines.forEach((line, index) => { const lineNumber = index + 1; const trimmed = line.trim(); // Detect loops that call external functions if (/for\s*\(|\.forEach\s*\(|\.map\s*\(|while\s*\(/.test(trimmed)) { const functionCalls = extractFunctionCalls(trimmed); functionCalls.forEach(funcCall => { // Check if this function has high complexity in other files const complexFunction = findComplexFunction(funcCall, fileMap); if (complexFunction && complexFunction.hasNestedLoops) { issues.push({ type: 'cross_file_complexity', severity: 'HIGH', category: 'Algorithm', location: `${filePath}:${lineNumber}`, line: lineNumber, code: trimmed, description: `Loop calls function '${funcCall}' which contains nested loops (${complexFunction.complexity})`, summary: 'Cross-file nested complexity pattern detected', recommendation: `Optimize function '${funcCall}' or cache results to avoid repeated complex operations`, effort: 4, impact: 'Multiplicative complexity across files', estimatedSavings: '60-90% latency reduction' }); } }); } }); return issues; } module.exports = detectCrossFileComplexity;