Skip to content

Commit

Permalink
Unwrap object
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkwaiblinger committed Jul 16, 2023
1 parent d4c0d43 commit 81e28f7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/eslint-plugin/src/rules/no-floating-promises.ts
Expand Up @@ -255,9 +255,10 @@ export default util.createRule<Options, MessageId>({
}

// `x.finally()` is transparent to resolution of the promise, so check `x`.
const promiseFinally = parsePromiseFinallyCall(node);
if (promiseFinally) {
return isUnhandledPromise(checker, promiseFinally.object);
// ("object" in this context is the `x` in `x.finally()`)
const promiseFinallyObject = getObjectFromFinallyCall(node);
if (promiseFinallyObject) {
return isUnhandledPromise(checker, promiseFinallyObject);
}

// All other cases are unhandled.
Expand Down Expand Up @@ -384,12 +385,12 @@ function getRejectionHandlerFromThenCall(
}
}

function parsePromiseFinallyCall(
function getObjectFromFinallyCall(
expression: TSESTree.CallExpression,
): { object: TSESTree.Expression } | undefined {
): TSESTree.Expression | undefined {
return expression.callee.type === AST_NODE_TYPES.MemberExpression &&
expression.callee.property.type === AST_NODE_TYPES.Identifier &&
expression.callee.property.name === 'finally'
? { object: expression.callee.object }
? expression.callee.object
: undefined;
}

0 comments on commit 81e28f7

Please sign in to comment.