Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(eslint-plugin): no-floating-promises - support chain expression #3826

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/eslint-plugin/src/rules/no-floating-promises.ts
Expand Up @@ -149,6 +149,7 @@ export default util.createRule<Options, MessageId>({
);
} 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
) {
Expand Down
33 changes: 15 additions & 18 deletions packages/eslint-plugin/tests/rules/no-floating-promises.test.ts
Expand Up @@ -317,24 +317,6 @@ async function test() {
return promise;
}
`,

// optional chaining
`
async function test() {
declare const returnsPromise: () => Promise<void> | null;
await returnsPromise?.();
returnsPromise()?.then(
() => {},
() => {},
);
returnsPromise()
?.then(() => {})
?.catch(() => {});
returnsPromise()?.catch(() => {});
returnsPromise()?.finally(() => {});
Comment on lines -325 to -334
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren't all of these valid still?
They all either are awaited, or have a catch/finally to close off the promise.

return returnsPromise();
}
`,
// ignoreIIFE
{
code: `
Expand Down Expand Up @@ -896,5 +878,20 @@ async function test() {
},
],
},
{
// optional chaining
code: `
async function test() {
declare const returnsPromise: () => Promise<void> | null;
returnsPromise?.();
}
`,
errors: [
{
line: 4,
messageId: 'floatingVoid',
},
],
},
],
});