agentsqripts
Version:
Comprehensive static code analysis toolkit for identifying technical debt, security vulnerabilities, performance issues, and code quality problems
45 lines (38 loc) • 1.58 kB
JavaScript
/**
* @file Detect sequential awaits that could be parallelized
* @description Single responsibility: Find consecutive await statements that are independent
*/
const extractAwaitCall = require('../helpers/extractAwaitCall');
const areDependent = require('../helpers/areDependent');
function detectSequentialAwaits(lines, filePath) {
const issues = [];
for (let i = 0; i < lines.length - 1; i++) {
const line = lines[i];
const nextLine = lines[i + 1];
const lineNumber = i + 1;
// Look for consecutive await statements
if (/await\s+\w+/.test(line.trim()) && /await\s+\w+/.test(nextLine.trim())) {
// Check if they're independent (different variables/functions)
const firstAwait = extractAwaitCall(line);
const secondAwait = extractAwaitCall(nextLine);
if (firstAwait && secondAwait && !areDependent(firstAwait, secondAwait, lines, i)) {
issues.push({
type: 'sequential_awaits',
severity: 'MEDIUM',
category: 'Async',
location: `${filePath}:${lineNumber}`,
line: lineNumber,
code: line.trim(),
description: 'Sequential awaits that could run concurrently',
summary: 'Consecutive awaits that could run concurrently',
recommendation: 'Consider Promise.all if operations are independent',
effort: 1,
impact: '50–70% latency reduction for grouped ops',
estimatedSavings: '50-70% latency reduction'
});
}
}
}
return issues;
}
module.exports = detectSequentialAwaits;