diff --git a/packages/eslint-plugin/src/rules/start-function-prelude.js b/packages/eslint-plugin/src/rules/start-function-prelude.js index 150927f17de..8ad9a1bf0a7 100644 --- a/packages/eslint-plugin/src/rules/start-function-prelude.js +++ b/packages/eslint-plugin/src/rules/start-function-prelude.js @@ -60,38 +60,25 @@ export default { // Check for await usage before and within the region let foundAwait = false; - - // Use ESLint's selector to find await expressions + + // Use ESLint's built-in traversal const awaitExpressions = []; - context.getSourceCode().ast.body.forEach(node => { - if (node.type === 'ExportNamedDeclaration' && - node.declaration?.type === 'FunctionDeclaration' && - node.declaration.id.name === 'start') { - // Walk the function body looking for AwaitExpression nodes - const walk = node => { - if (node.type === 'AwaitExpression') { - awaitExpressions.push(node); - } - for (const key in node) { - if (typeof node[key] === 'object' && node[key] !== null) { - if (Array.isArray(node[key])) { - node[key].forEach(walk); - } else { - walk(node[key]); - } + context.getSourceCode().visitorKeys.BlockStatement.forEach(key => { + const bodyContent = functionNode.body[key]; + if (Array.isArray(bodyContent)) { + bodyContent.forEach(statement => { + if (statement.type === 'ExpressionStatement' && + statement.expression.type === 'AwaitExpression') { + const awaitLine = statement.loc.start.line; + const relativeLine = awaitLine - functionNode.loc.start.line; + if (relativeLine <= regionEndLine) { + foundAwait = true; } } - }; - walk(node.declaration.body); + }); } }); - foundAwait = awaitExpressions.some(node => { - const awaitLine = node.loc.start.line; - const relativeLine = awaitLine - functionNode.loc.start.line; - return relativeLine <= regionEndLine; - }); - if (foundAwait) { context.report({ node: functionNode,