Skip to content

Commit aef6e7d

Browse files
HenryBrown0ljharb
andcommitted
[Refactor] function-component-definition: exit early if no type params
Co-authored-by: HenryBrown0 <[email protected]> Co-authored-by: Jordan Harband <[email protected]>
1 parent 0714704 commit aef6e7d

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1717
### Changed
1818
* [Refactor] `propTypes`: extract type params to var ([#3634][] @HenryBrown0)
1919
* [Refactor] [`boolean-prop-naming`]: invert if statement ([#3634][] @HenryBrown0)
20+
* [Refactor] [`function-component-definition`]: exit early if no type params ([#3634][] @HenryBrown0)
2021

2122
[#3638]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3638
2223
[#3634]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3634

lib/rules/function-component-definition.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,12 @@ const UNNAMED_FUNCTION_TEMPLATES = {
3333
};
3434

3535
function hasOneUnconstrainedTypeParam(node) {
36-
if (node.typeParameters) {
37-
return (
38-
node.typeParameters.params.length === 1
39-
&& !node.typeParameters.params[0].constraint
40-
);
41-
}
36+
const nodeTypeParams = node.typeParameters;
4237

43-
return false;
38+
return nodeTypeParams
39+
&& nodeTypeParams.params
40+
&& nodeTypeParams.params.length === 1
41+
&& !nodeTypeParams.params[0].constraint;
4442
}
4543

4644
function hasName(node) {

0 commit comments

Comments
 (0)