From 9acafc9ed0c3f9a783b824d6eec38bfd69d3eed6 Mon Sep 17 00:00:00 2001 From: cartogram Date: Fri, 26 Apr 2019 18:46:46 -0400 Subject: [PATCH] Fix hook strict return on undefined retuns --- lib/rules/react-hooks-strict-return.js | 10 +++++++--- tests/lib/rules/react-hooks-strict-return.js | 10 ++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/rules/react-hooks-strict-return.js b/lib/rules/react-hooks-strict-return.js index aed185a0..b63bf8e6 100644 --- a/lib/rules/react-hooks-strict-return.js +++ b/lib/rules/react-hooks-strict-return.js @@ -72,9 +72,13 @@ module.exports = { }; function exceedsMaxReturnProperties(node, scope, max) { - const { - argument: {type, elements}, - } = node; + const {argument} = node; + + if (argument === null) { + return false; + } + + const {type, elements} = argument; if (type !== 'ArrayExpression') { return getProps(node, scope).length > max; diff --git a/tests/lib/rules/react-hooks-strict-return.js b/tests/lib/rules/react-hooks-strict-return.js index 16aa8b60..89ed4eb0 100644 --- a/tests/lib/rules/react-hooks-strict-return.js +++ b/tests/lib/rules/react-hooks-strict-return.js @@ -145,6 +145,16 @@ ruleTester.run('react-hooks-strict-return', rule, { }`, parser, }, + { + code: `function useHookWithNoReturn() {}`, + parser, + }, + { + code: `function useHookUndefinedReturn() { + return; + }`, + parser, + }, ], invalid: [ {