UNPKG

agentsqripts

Version:

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

41 lines (35 loc) 1.41 kB
/** * @file Detect unhandled promises * @description Single responsibility: Find promises without proper error handling */ function detectUnhandledPromises(lines, filePath) { const issues = []; for (let i = 0; i < lines.length; i++) { const line = lines[i]; const lineNumber = i + 1; const trimmed = line.trim(); // Look for Promise calls without await or .then() if (/\w+\s*\([^)]*\)\s*;?\s*$/.test(trimmed) && !trimmed.includes('await')) { // Check if this could be a promise-returning function const possiblePromise = /fetch\s*\(|axios\.|api\.|request\.|http\.|async\w+\s*\(/i.test(trimmed); if (possiblePromise && !trimmed.includes('.then') && !trimmed.includes('.catch')) { issues.push({ type: 'unhandled_promise', severity: 'MEDIUM', category: 'Async', location: `${filePath}:${lineNumber}`, line: lineNumber, code: trimmed, description: 'Potential unhandled promise - missing await or .then()', summary: 'Promise not properly handled', recommendation: 'Add await or .then()/.catch() to handle promise', effort: 1, impact: 'Prevents silent failures and improves error handling', estimatedSavings: 'improved error handling' }); } } } return issues; } module.exports = detectUnhandledPromises;