diff --git a/rules/consistent-function-scoping.js b/rules/consistent-function-scoping.js index 33f92102cb..26eee95746 100644 --- a/rules/consistent-function-scoping.js +++ b/rules/consistent-function-scoping.js @@ -105,7 +105,8 @@ const iifeFunctionTypes = new Set([ const isIife = node => node && iifeFunctionTypes.has(node.type) && node.parent && - node.parent.type === 'CallExpression'; + node.parent.type === 'CallExpression' && + node.parent.callee === node; function checkNode(node, scopeManager) { const scope = scopeManager.acquire(node); diff --git a/test/consistent-function-scoping.js b/test/consistent-function-scoping.js index 6754dee928..8afaca1c0b 100644 --- a/test/consistent-function-scoping.js +++ b/test/consistent-function-scoping.js @@ -222,7 +222,7 @@ ruleTester.run('consistent-function-scoping', rule, { function foo() {} }, []) `, - // IIEF + // IIFE outdent` (function() { function bar() {} @@ -547,6 +547,51 @@ ruleTester.run('consistent-function-scoping', rule, { })(); `, errors: [createError('function \'bar\'')] + }, + // #770 + { + code: outdent` + process.nextTick(() => { + function returnsZero() { + return true; + } + process.exitCode = returnsZero(); + }); + `, + errors: [createError('function \'returnsZero\'')] + }, + { + code: outdent` + foo( + // This is not IIFE + function() { + function bar() { + } + }, + // This is IIFE + (function() { + function baz() { + } + })(), + ) + `, + errors: [createError('function \'bar\'')] + }, + { + code: outdent` + // This is IIFE + (function() { + function bar() { + } + })( + // This is not IIFE + function() { + function baz() { + } + }, + ) + `, + errors: [createError('function \'baz\'')] } ] });