diff --git a/src/rules/promiseFunctionAsyncRule.ts b/src/rules/promiseFunctionAsyncRule.ts index 1627212e38c..60f1fa9a607 100644 --- a/src/rules/promiseFunctionAsyncRule.ts +++ b/src/rules/promiseFunctionAsyncRule.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { hasModifier } from "tsutils"; +import { hasModifier, isCallExpression } from "tsutils"; import * as ts from "typescript"; import * as Lint from "../index"; @@ -103,10 +103,11 @@ function walk(ctx: Lint.WalkContext, tc: ts.TypeChecker) { const { sourceFile, options } = ctx; return ts.forEachChild(sourceFile, function cb(node): void { if (options.has(node.kind)) { + const declaration = node as ts.FunctionLikeDeclaration; switch (node.kind) { case ts.SyntaxKind.MethodDeclaration: case ts.SyntaxKind.FunctionDeclaration: - if ((node as ts.FunctionLikeDeclaration).body === undefined) { + if (declaration.body === undefined) { break; } // falls through @@ -114,7 +115,8 @@ function walk(ctx: Lint.WalkContext, tc: ts.TypeChecker) { case ts.SyntaxKind.ArrowFunction: if ( !hasModifier(node.modifiers, ts.SyntaxKind.AsyncKeyword) && - returnsPromise(node as ts.FunctionLikeDeclaration, tc) + returnsPromise(declaration, tc) && + !isCallExpression(declaration.body as ts.Expression) ) { ctx.addFailure( node.getStart(sourceFile), diff --git a/test/rules/promise-function-async/test.ts.lint b/test/rules/promise-function-async/test.ts.lint index 692f314831e..f3bc9e6bec6 100644 --- a/test/rules/promise-function-async/test.ts.lint +++ b/test/rules/promise-function-async/test.ts.lint @@ -62,6 +62,9 @@ class Test { public nonAsyncNonPromiseMethod(n: number) { return n; } + + // single statement lamda functions that delegate to another promise-returning function are allowed + public delegatingMethod = () => this.asyncPromiseMethodB(1); } [0]: functions that return promises must be async