Skip to content

Commit

Permalink
Fix forbid-prop-types for arrayOf and instanceOf (fixes #230)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Sep 30, 2015
1 parent a2d9faa commit 00f716a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/rules/forbid-prop-types.js
Expand Up @@ -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');
Expand Down
34 changes: 34 additions & 0 deletions tests/lib/rules/forbid-prop-types.js
Expand Up @@ -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 <div />;',
' }',
'});'
].join('\n'),
ecmaFeatures: {
jsx: true
}
}],

invalid: [{
Expand Down Expand Up @@ -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 <div />;',
' }',
'});'
].join('\n'),
ecmaFeatures: {
jsx: true
},
options: [{
forbid: ['instanceOf']
}],
errors: 1
}]
});

0 comments on commit 00f716a

Please sign in to comment.