diff --git a/src/rules/noFloatingPromisesRule.ts b/src/rules/noFloatingPromisesRule.ts index c91fcb3a89b..add6701d8cb 100644 --- a/src/rules/noFloatingPromisesRule.ts +++ b/src/rules/noFloatingPromisesRule.ts @@ -59,7 +59,9 @@ function walk(ctx: Lint.WalkContext, tc: ts.TypeChecker) { return ts.forEachChild(ctx.sourceFile, function cb(node): void { if (isExpressionStatement(node)) { const { expression } = node; - if (isCallExpression(expression) && !isPromiseCatchCall(expression)) { + if (isCallExpression(expression) && + !isPromiseCatchCall(expression) && + !isPromiseThenCallWithRejectionHandler(expression)) { const { symbol } = tc.getTypeAtLocation(expression); if (symbol !== undefined && ctx.options.indexOf(symbol.name) !== -1) { ctx.addFailureAtNode(expression, Rule.FAILURE_STRING); @@ -73,3 +75,9 @@ function walk(ctx: Lint.WalkContext, tc: ts.TypeChecker) { function isPromiseCatchCall(expression: ts.CallExpression): boolean { return isPropertyAccessExpression(expression.expression) && expression.expression.name.text === "catch"; } + +function isPromiseThenCallWithRejectionHandler(expression: ts.CallExpression): boolean { + return isPropertyAccessExpression(expression.expression) && + expression.expression.name.text === "then" && + expression.arguments.length >= 2; +} diff --git a/test/rules/no-floating-promises/promises/test.ts.lint b/test/rules/no-floating-promises/promises/test.ts.lint index e5915a50ec4..145062f8c24 100644 --- a/test/rules/no-floating-promises/promises/test.ts.lint +++ b/test/rules/no-floating-promises/promises/test.ts.lint @@ -156,4 +156,6 @@ switch(foo) { returnsPromiseFunction().catch(e => { console.error(e.stack); }); -[0]: Promises must be handled appropriately \ No newline at end of file +returnsPromiseFunction().then(() => {}, e => { console.error(e.stack); }); + +[0]: Promises must be handled appropriately