Skip to content

Commit e68461f

Browse files
committed
Apply allowInPropTypes option to class property
1 parent 3008e85 commit e68461f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/rules/forbid-foreign-prop-types.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ module.exports = {
5252
return null;
5353
}
5454

55+
function findParentClassProperty(node) {
56+
let parent = node.parent;
57+
58+
while (parent && parent.type !== 'Program') {
59+
if (parent.type === 'ClassProperty') {
60+
return parent;
61+
}
62+
parent = parent.parent;
63+
}
64+
return null;
65+
}
66+
5567
function isAllowedAssignment(node) {
5668
if (!allowInPropTypes) {
5769
return false;
@@ -67,6 +79,16 @@ module.exports = {
6779
) {
6880
return true;
6981
}
82+
83+
const classProperty = findParentClassProperty(node);
84+
85+
if (
86+
classProperty &&
87+
classProperty.key &&
88+
classProperty.key.name === 'propTypes'
89+
) {
90+
return true;
91+
}
7092
return false;
7193
}
7294

0 commit comments

Comments
 (0)