agentsqripts
Version:
Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems
27 lines (22 loc) • 690 B
JavaScript
/**
* @file Check for unbounded loops
* @description Single responsibility: Check if a loop appears to be unbounded
*/
/**
* Checks if a loop appears to be unbounded
* @param {string} line - Line containing loop
* @returns {boolean} True if loop appears unbounded
*/
function isUnboundedLoop(line) {
const trimmed = line.trim();
// Infinite loops
if (/while\s*\(\s*(true|1)\s*\)|for\s*\(\s*;\s*;\s*\)/.test(trimmed)) {
return true;
}
// While loops without obvious limits
if (/while\s*\(/.test(trimmed)) {
return !(/\w+\s*<\s*\w+\.(length|size)|\.slice\(|\.take\(|limit|max|MAX_/i.test(trimmed));
}
return false;
}
module.exports = isUnboundedLoop;