diff --git a/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js b/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js index 72130f4b830a0..a9648151a2d77 100644 --- a/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js +++ b/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js @@ -1023,6 +1023,28 @@ const tests = { } `, }, + // Ignore arguments keyword for arrow functions. + { + code: ` + function Example() { + useEffect(() => { + arguments + }, []) + } + `, + }, + { + code: ` + function Example() { + useEffect(() => { + const bar = () => { + arguments; + }; + bar(); + }, []) + } + `, + }, ], invalid: [ { diff --git a/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js b/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js index 4a2c4f16ce335..37e315b429b3f 100644 --- a/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js +++ b/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js @@ -397,13 +397,14 @@ export default { }); } - // Ignore references to the function itself as it's not defined yet. const def = reference.resolved.defs[0]; - if ( - def != null && - def.node != null && - def.node.init === node.parent - ) { + + if (def == null) { + continue; + } + + // Ignore references to the function itself as it's not defined yet. + if (def.node != null && def.node.init === node.parent) { continue; }