Skip to content

Commit

Permalink
[Refactor] function-component-definition: exit early if no type params
Browse files Browse the repository at this point in the history
Co-authored-by: HenryBrown0 <26250092+HenryBrown0@users.noreply.github.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
  • Loading branch information
HenryBrown0 and ljharb committed Sep 24, 2023
1 parent 0714704 commit aef6e7d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
### Changed
* [Refactor] `propTypes`: extract type params to var ([#3634][] @HenryBrown0)
* [Refactor] [`boolean-prop-naming`]: invert if statement ([#3634][] @HenryBrown0)
* [Refactor] [`function-component-definition`]: exit early if no type params ([#3634][] @HenryBrown0)

[#3638]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3638
[#3634]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3634
Expand Down
12 changes: 5 additions & 7 deletions lib/rules/function-component-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ const UNNAMED_FUNCTION_TEMPLATES = {
};

function hasOneUnconstrainedTypeParam(node) {
if (node.typeParameters) {
return (
node.typeParameters.params.length === 1
&& !node.typeParameters.params[0].constraint
);
}
const nodeTypeParams = node.typeParameters;

return false;
return nodeTypeParams
&& nodeTypeParams.params
&& nodeTypeParams.params.length === 1
&& !nodeTypeParams.params[0].constraint;
}

function hasName(node) {
Expand Down

0 comments on commit aef6e7d

Please sign in to comment.