Skip to content

Commit

Permalink
Nested
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Mar 11, 2020
1 parent d03cde0 commit 0f5277e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion rules/consistent-function-scoping.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,16 @@ function checkReferences(scope, parent, scopeManager) {
);
}

const isArrowFunctionWithThis = scope =>
scope.type === 'function' &&
scope.block &&
scope.block.type === 'ArrowFunctionExpression' &&
scope.thisFound

function checkNode(node, scopeManager) {
const scope = scopeManager.acquire(node);
if (!scope || (node.type === 'ArrowFunctionExpression' && scope.thisFound)) {

if (!scope || isArrowFunctionWithThis(scope) || scope.childScopes.some(scope => isArrowFunctionWithThis(scope))) {
return true;
}

Expand Down
15 changes: 15 additions & 0 deletions test/consistent-function-scoping.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ ruleTester.run('consistent-function-scoping', rule, {
return doBar();
};
`,
outdent`
function doFoo(Foo) {
const doBar = () => () => this;
return doBar();
};
`,
// `arguments`
outdent`
function doFoo(Foo) {
Expand Down Expand Up @@ -343,6 +349,15 @@ ruleTester.run('consistent-function-scoping', rule, {
`,
errors: [arrowError]
},
{
code: outdent`
function doFoo(Foo) {
const doBar = () => (function() {return () => this})();
return doBar();
};
`,
errors: [arrowError]
},
// `arguments`
{
code: outdent`
Expand Down

0 comments on commit 0f5277e

Please sign in to comment.