From 3ac67d4bbdef94195612c380842501de5d664269 Mon Sep 17 00:00:00 2001 From: Matt Whitworth Date: Tue, 31 Aug 2021 08:44:30 +0100 Subject: [PATCH] fix(eslint-plugin): no-floating-promises - support chain expression --- .../src/rules/no-floating-promises.ts | 1 + .../tests/rules/no-floating-promises.test.ts | 33 +++++++++---------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/packages/eslint-plugin/src/rules/no-floating-promises.ts b/packages/eslint-plugin/src/rules/no-floating-promises.ts index 905dfd06fcf..12a446b37f3 100644 --- a/packages/eslint-plugin/src/rules/no-floating-promises.ts +++ b/packages/eslint-plugin/src/rules/no-floating-promises.ts @@ -149,6 +149,7 @@ export default util.createRule({ ); } else if ( node.type === AST_NODE_TYPES.MemberExpression || + node.type === AST_NODE_TYPES.ChainExpression || node.type === AST_NODE_TYPES.Identifier || node.type === AST_NODE_TYPES.NewExpression ) { diff --git a/packages/eslint-plugin/tests/rules/no-floating-promises.test.ts b/packages/eslint-plugin/tests/rules/no-floating-promises.test.ts index e7dfe710f15..c46fed955b2 100644 --- a/packages/eslint-plugin/tests/rules/no-floating-promises.test.ts +++ b/packages/eslint-plugin/tests/rules/no-floating-promises.test.ts @@ -317,24 +317,6 @@ async function test() { return promise; } `, - - // optional chaining - ` -async function test() { - declare const returnsPromise: () => Promise | null; - await returnsPromise?.(); - returnsPromise()?.then( - () => {}, - () => {}, - ); - returnsPromise() - ?.then(() => {}) - ?.catch(() => {}); - returnsPromise()?.catch(() => {}); - returnsPromise()?.finally(() => {}); - return returnsPromise(); -} - `, // ignoreIIFE { code: ` @@ -896,5 +878,20 @@ async function test() { }, ], }, + { + // optional chaining + code: ` + async function test() { + declare const returnsPromise: () => Promise | null; + returnsPromise?.(); + } + `, + errors: [ + { + line: 4, + messageId: 'floatingVoid', + }, + ], + }, ], });