Skip to content

Commit 67d73aa

Browse files
tylerlapradeljharb
authored andcommitted
[Fix] sort-prop-types: Check for undefined before accessing node.typeAnnotation.typeAnnotation
1 parent 51d342b commit 67d73aa

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
88
### Fixed
99

1010
* [`prop-types`]: fix `className` missing in prop validation false negative ([#3749] @akulsr0)
11+
* [`sort-prop-types`]: Check for undefined before accessing `node.typeAnnotation.typeAnnotation` ([#3779] @tylerlaprade)
1112

13+
[#3779]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3779
1214
[#3749]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3749
1315

1416
## [7.34.3] - 2024.06.18

lib/rules/sort-prop-types.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,10 @@ module.exports = {
230230
}
231231

232232
function handleFunctionComponent(node) {
233-
const firstArg = node.params[0].typeAnnotation && node.params[0].typeAnnotation.typeAnnotation;
233+
const firstArg = node.params
234+
&& node.params.length > 0
235+
&& node.params[0].typeAnnotation
236+
&& node.params[0].typeAnnotation.typeAnnotation;
234237
if (firstArg && firstArg.type === 'TSTypeReference') {
235238
const propType = typeAnnotations.get(firstArg.typeName.name)
236239
&& typeAnnotations.get(firstArg.typeName.name)[0];

tests/lib/rules/sort-prop-types.js

+8
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,14 @@ ruleTester.run('sort-prop-types', rule, {
493493
`,
494494
features: ['types'],
495495
options: [{ checkTypes: false }],
496+
},
497+
{
498+
code: `
499+
function Foo() {
500+
return <div />;
501+
}
502+
`,
503+
options: [{ checkTypes: true }],
496504
}
497505
)),
498506
invalid: parsers.all([].concat(

0 commit comments

Comments
 (0)