Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Fix hook strict return on undefined returns #251

Merged
merged 1 commit into from
Apr 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/rules/react-hooks-strict-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/rules/react-hooks-strict-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ ruleTester.run('react-hooks-strict-return', rule, {
}`,
parser,
},
{
code: `function useHookWithNoReturn() {}`,
parser,
},
{
code: `function useHookUndefinedReturn() {
return;
}`,
parser,
},
],
invalid: [
{
Expand Down