Skip to content

Commit

Permalink
chore: tag function
Browse files Browse the repository at this point in the history
  • Loading branch information
arka1002 committed Apr 29, 2024
1 parent 171701b commit ecd31e3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/eslint-plugin/src/rules/no-floating-promises.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,15 @@ export default createRule<Options, MessageId>({
// All other cases are unhandled.
return { isUnhandled: true };
} else if (node.type === AST_NODE_TYPES.TaggedTemplateExpression) {
if (
doesTypeMatchSpecifier(
services,
allowForKnownSafePromises,
services.getTypeAtLocation(node),
)
) {
return { isUnhandled: false };
}
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
Expand Down
19 changes: 19 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 @@ -694,6 +694,16 @@ type Foo<T> = Promise<T> & { hey?: string };
},
{
code: `
type SafePromise = Promise<number> & { __linterBrands?: string };
declare const myTag: (strings: TemplateStringsArray) => SafePromise;
myTag\`abc\`;
`,
options: [
{ allowForKnownSafePromises: [{ from: 'file', name: 'SafePromise' }] },
],
},
{
code: `
declare const myTag: (strings: TemplateStringsArray) => Promise<void>;
myTag\`abc\`.catch(() => {});
`,
Expand Down Expand Up @@ -2153,5 +2163,14 @@ type Foo<T> = Promise<T> & { hey?: string };
options: [{ allowForKnownSafePromises: [{ from: 'file', name: 'Bar' }] }],
errors: [{ line: 3, messageId: 'floatingPromiseArrayVoid' }],
},
{
code: `
type SafePromise = Promise<number> & { __linterBrands?: string };
declare const myTag: (strings: TemplateStringsArray) => SafePromise;
myTag\`abc\`;
`,
options: [{ allowForKnownSafePromises: [{ from: 'file', name: 'Foo' }] }],
errors: [{ line: 4, messageId: 'floatingVoid' }],
},
],
});

0 comments on commit ecd31e3

Please sign in to comment.