diff --git a/lib/rules/no-loop-func.js b/lib/rules/no-loop-func.js index daf25d4cc53..58cf3360d86 100644 --- a/lib/rules/no-loop-func.js +++ b/lib/rules/no-loop-func.js @@ -21,7 +21,7 @@ function isIIFE(node) { /** * Gets the containing loop node of a specified node. * - * We don't need to check nested functions, so this ignores those. + * We don't need to check nested functions, so this ignores those, with the exception of IIFE. * `Scope.through` contains references of nested functions. * @param {ASTNode} node An AST node to get. * @returns {ASTNode|null} The containing loop node of the specified node, or @@ -56,9 +56,12 @@ function getContainingLoopNode(node) { case "ArrowFunctionExpression": case "FunctionExpression": case "FunctionDeclaration": + + // We need to check nested functions only in case of IIFE. if (isIIFE(node)) { break; } + return null; default: break;