UNPKG

agentsqripts

Version:

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

29 lines (25 loc) 642 B
/** * @file Get loop depth from ancestors * @description Single responsibility: Calculate the nesting depth of loops */ /** * Get the loop depth for a node * @param {Array} ancestors - Array of ancestor nodes * @returns {number} Number of nested loops */ function getLoopDepth(ancestors) { if (!ancestors || !Array.isArray(ancestors)) { return 0; } const loopTypes = [ 'ForStatement', 'ForInStatement', 'ForOfStatement', 'WhileStatement', 'DoWhileStatement' ]; return ancestors.filter(ancestor => ancestor && loopTypes.includes(ancestor.type) ).length; } module.exports = getLoopDepth;