Skip to content

Commit

Permalink
fix(eslint-plugin): [no-floating-promises] handle TaggedTemplateExpre…
Browse files Browse the repository at this point in the history
…ssion (typescript-eslint#8758)

* fix(eslint-plugin): [no-floating-promises] handle TaggedTemplateExpression

* Improve test cases
  • Loading branch information
naruaway authored and peanutenthusiast committed Mar 27, 2024
1 parent 89c4052 commit 68ffc45
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/eslint-plugin/src/rules/no-floating-promises.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ export default createRule<Options, MessageId>({

// All other cases are unhandled.
return { isUnhandled: true };
} else if (node.type === AST_NODE_TYPES.TaggedTemplateExpression) {
return { isUnhandled: true };
} else if (node.type === AST_NODE_TYPES.ConditionalExpression) {
// We must be getting the promise-like value from one of the branches of the
// ternary. Check them directly.
Expand Down
49 changes: 49 additions & 0 deletions packages/eslint-plugin/tests/rules/no-floating-promises.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,18 @@ void promiseArray;
['I', 'am', 'just', 'an', 'array'];
`,
},
{
code: `
declare const myTag: (strings: TemplateStringsArray) => Promise<void>;
myTag\`abc\`.catch(() => {});
`,
},
{
code: `
declare const myTag: (strings: TemplateStringsArray) => string;
myTag\`abc\`;
`,
},
],

invalid: [
Expand Down Expand Up @@ -593,6 +605,43 @@ doSomething();
},
],
},
{
code: `
declare const myTag: (strings: TemplateStringsArray) => Promise<void>;
myTag\`abc\`;
`,
errors: [
{
line: 3,
messageId: 'floatingVoid',
},
],
},
{
code: `
declare const myTag: (strings: TemplateStringsArray) => Promise<void>;
myTag\`abc\`.then(() => {});
`,
errors: [
{
line: 3,
messageId: 'floatingVoid',
},
],
},
{
code: `
declare const myTag: (strings: TemplateStringsArray) => Promise<void>;
myTag\`abc\`.finally(() => {});
`,
errors: [
{
line: 3,
messageId: 'floatingVoid',
},
],
},

{
options: [{ ignoreVoid: true }],
code: `
Expand Down

0 comments on commit 68ffc45

Please sign in to comment.