From 0a348654e77cb3bab855026c4c2e3a84fa509021 Mon Sep 17 00:00:00 2001 From: yeonjuan Date: Wed, 17 Jun 2020 13:01:25 +0900 Subject: [PATCH] [eslint-plugin-react-hooks]: handling sparse array when no-inline callback --- .../__tests__/ESLintRuleExhaustiveDeps-test.js | 14 ++++++++++++++ .../src/ExhaustiveDeps.js | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js b/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js index c8204283986e..9322952fa4f3 100644 --- a/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js +++ b/packages/eslint-plugin-react-hooks/__tests__/ESLintRuleExhaustiveDeps-test.js @@ -369,6 +369,20 @@ const tests = { } `, }, + { + code: normalizeIndent` + function MyComponent({myEffect}) { + useEffect(myEffect, [,myEffect]); + } + `, + }, + { + code: normalizeIndent` + function MyComponent({myEffect}) { + useEffect(myEffect, [,myEffect,,]); + } + `, + }, { code: normalizeIndent` let local = {}; diff --git a/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js b/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js index 6fc155d45598..33ff43a66355 100644 --- a/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js +++ b/packages/eslint-plugin-react-hooks/src/ExhaustiveDeps.js @@ -145,7 +145,7 @@ export default { if ( declaredDependenciesNode.elements && declaredDependenciesNode.elements.some( - el => el.type === 'Identifier' && el.name === callback.name, + el => el && el.type === 'Identifier' && el.name === callback.name, ) ) { // If it's already in the list of deps, we don't care because