Skip to content

Commit

Permalink
consistent-function-scoping: Fix wrong detect of IIFE (#772)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Jun 21, 2020
1 parent 4ed2adf commit f7127da
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
3 changes: 2 additions & 1 deletion rules/consistent-function-scoping.js
Expand Up @@ -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);
Expand Down
47 changes: 46 additions & 1 deletion test/consistent-function-scoping.js
Expand Up @@ -222,7 +222,7 @@ ruleTester.run('consistent-function-scoping', rule, {
function foo() {}
}, [])
`,
// IIEF
// IIFE
outdent`
(function() {
function bar() {}
Expand Down Expand Up @@ -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\'')]
}
]
});
Expand Down

0 comments on commit f7127da

Please sign in to comment.