Skip to content

Commit 09c1513

Browse files
committed
Fix hasOwnProperty that is taken for a prop (fixes #102)
1 parent eebb1d9 commit 09c1513

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/rules/prop-types.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ module.exports = function(context) {
126126

127127
switch (type) {
128128
case 'direct':
129+
// Ignore Object methods
130+
if (Object.prototype[node.parent.property.name]) {
131+
break;
132+
}
129133
usedPropTypes.push({
130134
name: node.parent.property.name,
131135
node: node.parent.property

tests/lib/rules/prop-types.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,24 @@ eslintTester.addRuleTest('lib/rules/prop-types', {
235235
classes: true,
236236
jsx: true
237237
}
238+
}, {
239+
code: [
240+
'class Hello extends React.Component {',
241+
' render() {',
242+
' if (this.props.hasOwnProperty(\'firstname\')) {',
243+
' return <div>Hello {this.props.firstname}</div>;',
244+
' }',
245+
' return <div>Hello</div>;',
246+
' }',
247+
'}',
248+
'Hello.propTypes = {',
249+
' \'firstname\': React.PropTypes.string',
250+
'};'
251+
].join('\n'),
252+
ecmaFeatures: {
253+
classes: true,
254+
jsx: true
255+
}
238256
}
239257
],
240258

0 commit comments

Comments
 (0)