UNPKG

agentsqripts

Version:

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

39 lines (33 loc) 1.04 kB
/** * @file Get loop body range * @description Single responsibility: Determine the range of a loop body */ /** * Get loop body range * @param {string[]} lines - Array of code lines * @param {number} loopStartIndex - Index where loop starts * @param {number} maxLines - Maximum lines to check (default 10) * @returns {{start: number, end: number}} Loop body range */ function getLoopBodyRange(lines, loopStartIndex, maxLines = 10) { const start = loopStartIndex + 1; const end = Math.min(start + maxLines, lines.length); // Try to find actual closing brace let braceCount = 0; let foundStart = false; for (let i = loopStartIndex; i < Math.min(loopStartIndex + 20, lines.length); i++) { const line = lines[i]; if (line.includes('{')) { braceCount++; foundStart = true; } if (line.includes('}')) { braceCount--; if (foundStart && braceCount === 0) { return { start, end: i }; } } } return { start, end }; } module.exports = getLoopBodyRange;