Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consistent-function-scoping: Fix wrong detect of IIFE #772

Merged
merged 6 commits into from Jun 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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