Skip to content

Commit f7127da

Browse files
authored
consistent-function-scoping: Fix wrong detect of IIFE (#772)
1 parent 4ed2adf commit f7127da

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

rules/consistent-function-scoping.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ const iifeFunctionTypes = new Set([
105105
const isIife = node => node &&
106106
iifeFunctionTypes.has(node.type) &&
107107
node.parent &&
108-
node.parent.type === 'CallExpression';
108+
node.parent.type === 'CallExpression' &&
109+
node.parent.callee === node;
109110

110111
function checkNode(node, scopeManager) {
111112
const scope = scopeManager.acquire(node);

test/consistent-function-scoping.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ ruleTester.run('consistent-function-scoping', rule, {
222222
function foo() {}
223223
}, [])
224224
`,
225-
// IIEF
225+
// IIFE
226226
outdent`
227227
(function() {
228228
function bar() {}
@@ -547,6 +547,51 @@ ruleTester.run('consistent-function-scoping', rule, {
547547
})();
548548
`,
549549
errors: [createError('function \'bar\'')]
550+
},
551+
// #770
552+
{
553+
code: outdent`
554+
process.nextTick(() => {
555+
function returnsZero() {
556+
return true;
557+
}
558+
process.exitCode = returnsZero();
559+
});
560+
`,
561+
errors: [createError('function \'returnsZero\'')]
562+
},
563+
{
564+
code: outdent`
565+
foo(
566+
// This is not IIFE
567+
function() {
568+
function bar() {
569+
}
570+
},
571+
// This is IIFE
572+
(function() {
573+
function baz() {
574+
}
575+
})(),
576+
)
577+
`,
578+
errors: [createError('function \'bar\'')]
579+
},
580+
{
581+
code: outdent`
582+
// This is IIFE
583+
(function() {
584+
function bar() {
585+
}
586+
})(
587+
// This is not IIFE
588+
function() {
589+
function baz() {
590+
}
591+
},
592+
)
593+
`,
594+
errors: [createError('function \'baz\'')]
550595
}
551596
]
552597
});

0 commit comments

Comments
 (0)