From e68461ff3b2d8fa9228eae4479146a638c5d7f0c Mon Sep 17 00:00:00 2001 From: Yo Takezawa Date: Mon, 12 Nov 2018 11:13:21 +0900 Subject: [PATCH] Apply allowInPropTypes option to class property --- lib/rules/forbid-foreign-prop-types.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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; }