Skip to content

Commit

Permalink
Fix require-default-props error message for quoted props (fixes #1161)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed May 11, 2017
1 parent f7fb96b commit af68f88
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/require-default-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ module.exports = {

return props.map(function(property) {
return {
name: property.key.name,
name: property.key.name || property.key.value,
isRequired: isRequiredPropType(property.value),
node: property
};
Expand Down
18 changes: 18 additions & 0 deletions tests/lib/rules/require-default-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -1805,6 +1805,24 @@ ruleTester.run('require-default-props', rule, {
errors: [{
message: 'propType "name" is not required, but has no corresponding defaultProp declaration.'
}]
},
{
code: [
'class Hello extends React.Component {',
' static get propTypes() {',
' return {',
' \'first-name\': PropTypes.string',
' };',
' }',
' render() {',
' return <div>Hello {this.props[\'first-name\']}</div>;',
' }',
'}'
].join('\n'),
parser: 'babel-eslint',
errors: [{
message: 'propType "first-name" is not required, but has no corresponding defaultProp declaration.'
}]
}
]
});

0 comments on commit af68f88

Please sign in to comment.