diff --git a/packages/eslint-plugin/src/rules/no-floating-promises.ts b/packages/eslint-plugin/src/rules/no-floating-promises.ts index c3ee7ffccf3..2c5a41b10d6 100644 --- a/packages/eslint-plugin/src/rules/no-floating-promises.ts +++ b/packages/eslint-plugin/src/rules/no-floating-promises.ts @@ -12,6 +12,11 @@ type Options = [ type MessageId = 'floating' | 'floatingVoid' | 'floatingFixVoid'; +const possibleIifeCalleType = new Set([ + 'FunctionExpression', + 'ArrowFunctionExpression', +]); + export default util.createRule({ name: 'no-floating-promises', meta: { @@ -54,6 +59,10 @@ export default util.createRule({ ExpressionStatement(node): void { const { expression } = parserServices.esTreeNodeToTSNodeMap.get(node); + if (isIife(node)) { + return; + } + if (isUnhandledPromise(checker, expression)) { if (options.ignoreVoid) { context.report({ @@ -80,6 +89,15 @@ export default util.createRule({ }, }; + function isIife(node: ts.Node): Boolean { + if (node?.expression.type === 'CallExpression') { + if (possibleIifeCalleType.has(node?.expression?.callee.type)) { + return true; + } + } + return false; + } + function isUnhandledPromise( checker: ts.TypeChecker, node: ts.Node, diff --git a/packages/eslint-plugin/tests/rules/no-floating-promises.test.ts b/packages/eslint-plugin/tests/rules/no-floating-promises.test.ts index c7e688c9852..20953bcb232 100644 --- a/packages/eslint-plugin/tests/rules/no-floating-promises.test.ts +++ b/packages/eslint-plugin/tests/rules/no-floating-promises.test.ts @@ -428,10 +428,6 @@ async function test() { } `, errors: [ - { - line: 3, - messageId: 'floating', - }, { line: 4, messageId: 'floating',