Skip to content

Commit

Permalink
Apply allowInPropTypes option to class property
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheile committed Nov 12, 2018
1 parent 3008e85 commit e68461f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/rules/forbid-foreign-prop-types.js
Expand Up @@ -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;
Expand All @@ -67,6 +79,16 @@ module.exports = {
) {
return true;
}

const classProperty = findParentClassProperty(node);

if (
classProperty &&
classProperty.key &&
classProperty.key.name === 'propTypes'
) {
return true;
}
return false;
}

Expand Down

0 comments on commit e68461f

Please sign in to comment.