diff --git a/lib/rules/forbid-foreign-prop-types.js b/lib/rules/forbid-foreign-prop-types.js index ba944f94e8..b5a829f631 100644 --- a/lib/rules/forbid-foreign-prop-types.js +++ b/lib/rules/forbid-foreign-prop-types.js @@ -52,6 +52,18 @@ module.exports = { return null; } + function findParentClassProperty(node) { + let parent = node.parent; + + while (parent && parent.type !== 'Program') { + if (parent.type === 'ClassProperty') { + return parent; + } + parent = parent.parent; + } + return null; + } + function isAllowedAssignment(node) { if (!allowInPropTypes) { return false; @@ -67,6 +79,16 @@ module.exports = { ) { return true; } + + const classProperty = findParentClassProperty(node); + + if ( + classProperty && + classProperty.key && + classProperty.key.name === 'propTypes' + ) { + return true; + } return false; }