8000 fix(eslint-plugin): [no-floating-promises] handle TaggedTemplateExpression by naruaway · Pull Request #8758 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

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

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

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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