Skip to content

Commit

Permalink
Fix prop-types crash when destructuring props with spread only
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Jun 16, 2016
1 parent cd5ef2b commit e341dfa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ module.exports = Components.detect(function(context, components, utils) {
for (var i = 0, j = node.id.properties.length; i < j; i++) {
// let {props: {firstname}} = this
var thisDestructuring = (
!hasSpreadOperator(node.id.properties[i]) &&
(node.id.properties[i].key.name === 'props' || node.id.properties[i].key.value === 'props') &&
node.id.properties[i].value.type === 'ObjectPattern'
);
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,15 @@ ruleTester.run('prop-types', rule, {
'class Something extends Component {}'
].join('\n'),
parser: 'babel-eslint'
}, {
// Should not find any used props
code: [
'function Hello(props) {',
' const {...rest} = props;',
' return <div>Hello</div>;',
'}'
].join('\n'),
parserOptions: parserOptions
}
],

Expand Down

0 comments on commit e341dfa

Please sign in to comment.