diff --git a/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js b/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js index 8a72692335ed2..8c3aa19d907d0 100644 --- a/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js +++ b/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js @@ -1024,6 +1024,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; }