Skip to content

Commit

Permalink
[Fix] forbid-prop-types: warn on destructured values as well
Browse files Browse the repository at this point in the history
Fixes #2662.

Co-authored-by: Alex Kovar <ajkovar@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
  • Loading branch information
ajkovar and ljharb committed Jun 16, 2020
1 parent b8e91a5 commit 08cdd39
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
5 changes: 1 addition & 4 deletions lib/rules/forbid-prop-types.js
Expand Up @@ -93,10 +93,7 @@ module.exports = {
) {
value = value.object;
}
if (
value.type === 'CallExpression'
&& value.callee.type === 'MemberExpression'
) {
if (value.type === 'CallExpression') {
value = value.callee;
}
if (value.property) {
Expand Down
37 changes: 37 additions & 0 deletions tests/lib/rules/forbid-prop-types.js
Expand Up @@ -1460,5 +1460,42 @@ ruleTester.run('forbid-prop-types', rule, {
checkChildContextTypes: true
}],
errors: 1
}, {
code: [
'import { object, string } from "prop-types";',
'function C({ a, b }) { return [a, b]; }',
'C.propTypes = {',
' a: object,',
' b: string',
'};'
].join('\n'),
options: [{
forbid: ['object']
}],
errors: 1
}, {
code: [
'import { objectOf, any } from "prop-types";',
'function C({ a }) { return a; }',
'C.propTypes = {',
' a: objectOf(any)',
'};'
].join('\n'),
options: [{
forbid: ['any']
}],
errors: 1
}, {
code: [
'import { objectOf, any } from "prop-types";',
'function C({ a }) { return a; }',
'C.propTypes = {',
' a: objectOf(any)',
'};'
].join('\n'),
options: [{
forbid: ['objectOf']
}],
errors: 1
}]
});

0 comments on commit 08cdd39

Please sign in to comment.