Skip to content

Commit 1ced710

Browse files
committed
Fix no-unused-prop-types crash with Flow spread operator (fixes #1178
1 parent 159d0e5 commit 1ced710

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/rules/no-unused-prop-types.js

+4
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,10 @@ module.exports = {
678678
switch (propTypes && propTypes.type) {
679679
case 'ObjectTypeAnnotation':
680680
iterateProperties(propTypes.properties, function(key, value) {
681+
if (!value) {
682+
ignorePropsValidation = true;
683+
return;
684+
}
681685
var types = buildTypeAnnotationDeclarationTypes(value, key);
682686
if (types === true) {
683687
types = {};

tests/lib/rules/no-unused-prop-types.js

+28
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,34 @@ ruleTester.run('no-unused-prop-types', rule, {
14111411
' bar: PropTypes.bool',
14121412
'};'
14131413
].join('\n')
1414+
}, {
1415+
code: [
1416+
'type Person = {',
1417+
' ...data,',
1418+
' lastname: string',
1419+
'};',
1420+
'class Hello extends React.Component {',
1421+
' props: Person;',
1422+
' render () {',
1423+
' return <div>Hello {this.props.firstname}</div>;',
1424+
' }',
1425+
'}'
1426+
].join('\n'),
1427+
parser: 'babel-eslint'
1428+
}, {
1429+
code: [
1430+
'type Person = {|',
1431+
' ...data,',
1432+
' lastname: string',
1433+
'|};',
1434+
'class Hello extends React.Component {',
1435+
' props: Person;',
1436+
' render () {',
1437+
' return <div>Hello {this.props.firstname}</div>;',
1438+
' }',
1439+
'}'
1440+
].join('\n'),
1441+
parser: 'babel-eslint'
14141442
}
14151443
],
14161444

0 commit comments

Comments
 (0)