diff --git a/lib/rules/forbid-prop-types.js b/lib/rules/forbid-prop-types.js index e655d55839..1d8ae8b9e9 100644 --- a/lib/rules/forbid-prop-types.js +++ b/lib/rules/forbid-prop-types.js @@ -61,6 +61,12 @@ module.exports = function(context) { ) { declaration.value = declaration.value.object; } + if ( + declaration.value.type === 'CallExpression' && + declaration.value.callee.type === 'MemberExpression' + ) { + declaration.value = declaration.value.callee; + } if (isForbidden(declaration.value.property.name)) { context.report(declaration, 'Prop type `' + declaration.value.property.name + '` is forbidden'); diff --git a/tests/lib/rules/forbid-prop-types.js b/tests/lib/rules/forbid-prop-types.js index 42caff7151..716ba25cd4 100644 --- a/tests/lib/rules/forbid-prop-types.js +++ b/tests/lib/rules/forbid-prop-types.js @@ -176,6 +176,21 @@ ruleTester.run('forbid-prop-types', rule, { experimentalObjectRestSpread: true, jsx: true } + }, { + code: [ + 'var Hello = React.createClass({', + ' propTypes: {', + ' retailer: PropTypes.instanceOf(Map).isRequired,', + ' requestRetailer: PropTypes.func.isRequired', + ' },', + ' render: function() {', + ' return
;', + ' }', + '});' + ].join('\n'), + ecmaFeatures: { + jsx: true + } }], invalid: [{ @@ -421,5 +436,24 @@ ruleTester.run('forbid-prop-types', rule, { jsx: true }, errors: 2 + }, { + code: [ + 'var Hello = React.createClass({', + ' propTypes: {', + ' retailer: PropTypes.instanceOf(Map).isRequired,', + ' requestRetailer: PropTypes.func.isRequired', + ' },', + ' render: function() {', + ' return
;', + ' }', + '});' + ].join('\n'), + ecmaFeatures: { + jsx: true + }, + options: [{ + forbid: ['instanceOf'] + }], + errors: 1 }] });