UNPKG

agentsqripts

Version:

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

50 lines (42 loc) 1.62 kB
/** * @file Check if function is async * @description Single responsibility: Determine if a function node is async or returns a promise */ /** * Check if a function is async or returns a promise * @param {Object} node - AST node * @returns {boolean} True if async or promise-returning */ function isAsyncFunction(node) { if (!node) return false; // Direct async function if (node.async) return true; // Check if it's a known async method with proper context if (node.type === 'MemberExpression' && node.property) { const methodName = node.property.name; // Check for promise-based APIs if (node.object && node.object.type === 'MemberExpression' && node.object.property && node.object.property.name === 'promises') { // This is fs.promises.*, fetch.promises.*, etc - these are async const asyncPromiseMethods = [ 'readFile', 'writeFile', 'readdir', 'stat', 'unlink', 'mkdir' ]; return asyncPromiseMethods.includes(methodName); } // Other known async methods const asyncMethods = [ 'fetch', 'save', 'find', 'findOne', 'create', 'update', 'delete', 'query', 'execute', 'connect', 'disconnect' ]; return asyncMethods.includes(methodName); } // Check if function name strongly suggests async if (node.type === 'Identifier') { const name = node.name; // Only match explicit async patterns, not generic 'get' prefix return name.includes('Async') || name.endsWith('Async') || name === 'fetch' || name.startsWith('fetch'); } return false; } module.exports = isAsyncFunction;