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 fcae315
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 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
1 change: 0 additions & 1 deletion test/mocha.opts
@@ -1 +0,0 @@
--reporter=min

0 comments on commit fcae315

Please sign in to comment.