Skip to content

Commit

Permalink
Merge d03cde0 into 4c48c02
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Mar 11, 2020
2 parents 4c48c02 + d03cde0 commit 7a787da
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rules/consistent-function-scoping.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function checkReferences(scope, parent, scopeManager) {

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

Expand Down
56 changes: 56 additions & 0 deletions test/consistent-function-scoping.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,20 @@ ruleTester.run('consistent-function-scoping', rule, {
return Bar;
};
`,
// `this`
outdent`
function doFoo(Foo) {
const doBar = () => this;
return doBar();
};
`,
// `arguments`
outdent`
function doFoo(Foo) {
const doBar = () => arguments;
return doBar();
};
`,
// #391
outdent`
const enrichErrors = (packageName, cliArgs, f) => async (...args) => {
Expand Down Expand Up @@ -308,6 +322,48 @@ ruleTester.run('consistent-function-scoping', rule, {
`,
errors: [arrowError]
},
// `this`
{
code: outdent`
function doFoo(Foo) {
function doBar() {
return this;
}
return doBar();
};
`,
errors: [functionError]
},
{
code: outdent`
function doFoo(Foo) {
const doBar = () => (function() {return this})();
return doBar();
};
`,
errors: [arrowError]
},
// `arguments`
{
code: outdent`
function doFoo(Foo) {
function doBar() {
return arguments;
}
return doBar();
};
`,
errors: [functionError]
},
{
code: outdent`
function doFoo(Foo) {
const doBar = () => (function() {return arguments})();
return doBar();
};
`,
errors: [arrowError]
},
{
code: outdent`
function doFoo(foo) {
Expand Down

0 comments on commit 7a787da

Please sign in to comment.