Skip to content

Commit

Permalink
Fix hasOwnProperty that is taken for a prop (fixes #102)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Jun 14, 2015
1 parent eebb1d9 commit 09c1513
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rules/prop-types.js
Expand Up @@ -126,6 +126,10 @@ module.exports = function(context) {

switch (type) {
case 'direct':
// Ignore Object methods
if (Object.prototype[node.parent.property.name]) {
break;
}
usedPropTypes.push({
name: node.parent.property.name,
node: node.parent.property
Expand Down
18 changes: 18 additions & 0 deletions tests/lib/rules/prop-types.js
Expand Up @@ -235,6 +235,24 @@ eslintTester.addRuleTest('lib/rules/prop-types', {
classes: true,
jsx: true
}
}, {
code: [
'class Hello extends React.Component {',
' render() {',
' if (this.props.hasOwnProperty(\'firstname\')) {',
' return <div>Hello {this.props.firstname}</div>;',
' }',
' return <div>Hello</div>;',
' }',
'}',
'Hello.propTypes = {',
' \'firstname\': React.PropTypes.string',
'};'
].join('\n'),
ecmaFeatures: {
classes: true,
jsx: true
}
}
],

Expand Down

0 comments on commit 09c1513

Please sign in to comment.