agentsqripts
Version:
Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems
50 lines (44 loc) • 1.67 kB
JavaScript
/**
* @file Fallback regex-based detection for non-parseable files
* @description Single responsibility: Detect recursion using regex patterns
*/
/**
* Fallback regex-based detection for non-parseable files
*/
function detectRecursiveRegex(content, filePath) {
const issues = [];
const lines = content.split('\n');
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const lineNumber = i + 1;
const trimmed = line.trim();
// Look for function definitions
const funcMatch = trimmed.match(/function\s+(\w+)|const\s+(\w+)\s*=.*=>|(\w+)\s*[:=]\s*function/);
if (funcMatch) {
const funcName = funcMatch[1] || funcMatch[2] || funcMatch[3];
// Look for recursive calls within next 20 lines
for (let j = i + 1; j < Math.min(i + 20, lines.length); j++) {
const innerLine = lines[j].trim();
if (innerLine.includes(funcName + '(')) {
issues.push({
type: 'recursive_pattern',
severity: 'MEDIUM',
category: 'Algorithm',
location: `${filePath}:${j + 1}`,
line: j + 1,
code: innerLine,
description: `Potential recursive call detected in function '${funcName}'`,
summary: 'Recursive pattern detected',
recommendation: 'Verify recursion has proper base case and consider iterative alternatives',
effort: 2,
impact: 'Potential performance and stack optimization',
estimatedSavings: '30-50% stack usage improvement'
});
break;
}
}
}
}
return issues;
}
module.exports = detectRecursiveRegex;