agentsqripts
Version:
Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems
31 lines (27 loc) • 752 B
JavaScript
/**
* @file Check if node is inside a loop
* @description Single responsibility: Determine if AST node is inside a loop structure
*/
/**
* Check if a node is inside a loop
* @param {Object} node - Current AST node
* @param {Array} ancestors - Array of ancestor nodes
* @returns {boolean} True if node is inside a loop
*/
function isInsideLoop(node, ancestors = []) {
if (!ancestors || !Array.isArray(ancestors)) {
return false;
}
const loopTypes = [
'ForStatement',
'ForInStatement',
'ForOfStatement',
'WhileStatement',
'DoWhileStatement'
];
// Check if any ancestor is a loop
return ancestors.some(ancestor =>
ancestor && loopTypes.includes(ancestor.type)
);
}
module.exports = isInsideLoop;