Skip to content

Commit

Permalink
Fix wrong prop-types detection (fixes #255)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Oct 18, 2015
1 parent 3cc654d commit fe1ef9b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ module.exports = function(context) {
* @returns {Boolean} True if we are using a prop, false if not.
*/
function isPropTypesUsage(node) {
var isClassUsage = node.object.type === 'ThisExpression' && node.property.name === 'props';
var isClassUsage = (
componentUtil.getNode(context, node) &&
node.object.type === 'ThisExpression' && node.property.name === 'props'
);
var isStatelessFunctionUsage = node.object.name === 'props';
return isClassUsage || isStatelessFunctionUsage;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,16 @@ ruleTester.run('prop-types', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
// Should not be detected as a component
code: [
'HelloJohn.prototype.render = function() {',
' return React.createElement(Hello, {',
' name: this.props.firstname',
' });',
'};'
].join('\n'),
parser: 'babel-eslint'
}
],

Expand Down

0 comments on commit fe1ef9b

Please sign in to comment.