Skip to content

Commit

Permalink
Forbid forbidden function argument #2662
Browse files Browse the repository at this point in the history
  • Loading branch information
ajkovar committed Jun 16, 2020
1 parent 08cdd39 commit eac5a43
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/rules/forbid-prop-types.js
Expand Up @@ -59,6 +59,15 @@ module.exports = {
return forbid.indexOf(type) >= 0;
}

function reportIfForbidden(type, declaration, target) {
if (isForbidden(type)) {
context.report({
node: declaration,
message: `Prop type \`${target}\` is forbidden`
});
}
}

function shouldCheckContextTypes(node) {
if (checkContextTypes && propsUtil.isContextTypesDeclaration(node)) {
return true;
Expand Down Expand Up @@ -94,19 +103,17 @@ module.exports = {
value = value.object;
}
if (value.type === 'CallExpression') {
value.arguments.forEach((arg) => {
reportIfForbidden(arg.name, declaration, target);
});
value = value.callee;
}
if (value.property) {
target = value.property.name;
} else if (value.type === 'Identifier') {
target = value.name;
}
if (isForbidden(target)) {
context.report({
node: declaration,
message: `Prop type \`${target}\` is forbidden`
});
}
reportIfForbidden(target, declaration, target);
});
}

Expand Down

0 comments on commit eac5a43

Please sign in to comment.