Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9e64bf1

Browse files
hristo-kanchevgaearon
authored andcommitted
[eslint-plugin-react-hooks] Fixed crash when referencing arguments in arrow functions. (facebook#16356)
* Fixed issue with def being undefined while referencing arguments. * Removed todo comment. * Skip exhaustive deps check if def is null. * Fixed code formatting in ExhaustiveDeps. * Removed unneeded comment in ExhaustiveDeps.
1 parent e308a03 commit 9e64bf1

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,28 @@ const tests = {
10231023
}
10241024
`,
10251025
},
1026+
// Ignore arguments keyword for arrow functions.
1027+
{
1028+
code: `
1029+
function Example() {
1030+
useEffect(() => {
1031+
arguments
1032+
}, [])
1033+
}
1034+
`,
1035+
},
1036+
{
1037+
code: `
1038+
function Example() {
1039+
useEffect(() => {
1040+
const bar = () => {
1041+
arguments;
1042+
};
1043+
bar();
1044+
}, [])
1045+
}
1046+
`,
1047+
},
10261048
],
10271049
invalid: [
10281050
{

packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,14 @@ export default {
397397
});
398398
}
399399

400-
// Ignore references to the function itself as it's not defined yet.
401400
const def = reference.resolved.defs[0];
402-
if (
403-
def != null &&
404-
def.node != null &&
405-
def.node.init === node.parent
406-
) {
401+
402+
if (def == null) {
403+
continue;
404+
}
405+
406+
// Ignore references to the function itself as it's not defined yet.
407+
if (def.node != null && def.node.init === node.parent) {
407408
continue;
408409
}
409410

0 commit comments

Comments
 (0)