UNPKG

agentsqripts

Version:

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

30 lines (25 loc) 799 B
/** * @file Check for small fixed loops * @description Single responsibility: Check if a loop has small fixed iterations */ /** * Checks if a loop is small/fixed iterations * @param {string} line - Line containing loop * @returns {boolean} True if loop has small fixed iterations */ function isSmallFixedLoop(line) { const trimmed = line.trim(); // Check for small fixed for loops (e.g., for(let i=0; i<3; i++)) if (/for\s*\([^;]+;\s*\w+\s*<\s*\d+\s*;/.test(trimmed)) { const match = trimmed.match(/<\s*(\d+)/); if (match && parseInt(match[1], 10) < 10) { return true; } } // Check for small known arrays if (/\[(.*?)\]\.forEach|\.slice\(\d+,\s*\d+\)\.forEach/.test(trimmed)) { return true; } return false; } module.exports = isSmallFixedLoop;