UNPKG

agentsqripts

Version:

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

23 lines (20 loc) 897 B
/** * @file Check for single-pass operations * @description Single responsibility: Identify operations that are O(n), not O(n²) */ /** * Check if this is a single-pass operation that shouldn't be flagged as O(n²) */ function isSinglePassOperation(line) { // These patterns are single-pass operations over arrays, not nested iterations const singlePassPatterns = [ /\.reduce\s*\([^)]*\)\s*[,;}]/, // reduce with end punctuation (not chained) /\.filter\s*\([^)]*\)\.length/, // filter().length (counting) /\w+\s*\+=.*\.filter\s*\(/, // assignment with filter /\w+\s*\+=.*\.reduce\s*\(/, // assignment with reduce /\.split\s*\([^)]*\)\.map\s*\(/, // split().map() chain - O(n), not O(n²) /\[.*\]\.map\s*\(/, // array literal map - single operation ]; return singlePassPatterns.some(pattern => pattern.test(line)); } module.exports = isSinglePassOperation;