Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Recognize promise then call with rejection handler as valid floating promise handling #3048

Merged
merged 3 commits into from
Jul 25, 2017
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/rules/noFloatingPromisesRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ function walk(ctx: Lint.WalkContext<string[]>, 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);
Expand All @@ -73,3 +75,9 @@ function walk(ctx: Lint.WalkContext<string[]>, 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;
}