Skip to content

Commit b040340

Browse files
naruawayyeonjuan
authored andcommitted
fix(eslint-plugin): [no-floating-promises] handle TaggedTemplateExpression (typescript-eslint#8758)
* fix(eslint-plugin): [no-floating-promises] handle TaggedTemplateExpression * Improve test cases
1 parent 32af4d5 commit b040340

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

Diff for: packages/eslint-plugin/src/rules/no-floating-promises.ts

+2
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ export default createRule<Options, MessageId>({
290290

291291
// All other cases are unhandled.
292292
return { isUnhandled: true };
293+
} else if (node.type === AST_NODE_TYPES.TaggedTemplateExpression) {
294+
return { isUnhandled: true };
293295
} else if (node.type === AST_NODE_TYPES.ConditionalExpression) {
294296
// We must be getting the promise-like value from one of the branches of the
295297
// ternary. Check them directly.

Diff for: packages/eslint-plugin/tests/rules/no-floating-promises.test.ts

+49
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,18 @@ void promiseArray;
504504
['I', 'am', 'just', 'an', 'array'];
505505
`,
506506
},
507+
{
508+
code: `
509+
declare const myTag: (strings: TemplateStringsArray) => Promise<void>;
510+
myTag\`abc\`.catch(() => {});
511+
`,
512+
},
513+
{
514+
code: `
515+
declare const myTag: (strings: TemplateStringsArray) => string;
516+
myTag\`abc\`;
517+
`,
518+
},
507519
],
508520

509521
invalid: [
@@ -593,6 +605,43 @@ doSomething();
593605
},
594606
],
595607
},
608+
{
609+
code: `
610+
declare const myTag: (strings: TemplateStringsArray) => Promise<void>;
611+
myTag\`abc\`;
612+
`,
613+
errors: [
614+
{
615+
line: 3,
616+
messageId: 'floatingVoid',
617+
},
618+
],
619+
},
620+
{
621+
code: `
622+
declare const myTag: (strings: TemplateStringsArray) => Promise<void>;
623+
myTag\`abc\`.then(() => {});
624+
`,
625+
errors: [
626+
{
627+
line: 3,
628+
messageId: 'floatingVoid',
629+
},
630+
],
631+
},
632+
{
633+
code: `
634+
declare const myTag: (strings: TemplateStringsArray) => Promise<void>;
635+
myTag\`abc\`.finally(() => {});
636+
`,
637+
errors: [
638+
{
639+
line: 3,
640+
messageId: 'floatingVoid',
641+
},
642+
],
643+
},
644+
596645
{
597646
options: [{ ignoreVoid: true }],
598647
code: `

0 commit comments

Comments
 (0)