Skip to content

Commit

Permalink
Do not modify AST directly (fixes jsx-eslint#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Oct 16, 2015
1 parent 7bbbda7 commit 9c42ae8
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/rules/forbid-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,25 @@ module.exports = function(context) {
function checkForbidden(declarations) {
declarations.forEach(function(declaration) {
var target;
var value = declaration.value;
if (
declaration.value.type === 'MemberExpression' &&
declaration.value.property &&
declaration.value.property.name &&
declaration.value.property.name === 'isRequired'
value.type === 'MemberExpression' &&
value.property &&
value.property.name &&
value.property.name === 'isRequired'
) {
declaration.value = declaration.value.object;
value = value.object;
}
if (
declaration.value.type === 'CallExpression' &&
declaration.value.callee.type === 'MemberExpression'
value.type === 'CallExpression' &&
value.callee.type === 'MemberExpression'
) {
declaration.value = declaration.value.callee;
value = value.callee;
}
if (declaration.value.property) {
target = declaration.value.property.name;
} else if (declaration.value.type === 'Identifier') {
target = declaration.value.name;
if (value.property) {
target = value.property.name;
} else if (value.type === 'Identifier') {
target = value.name;
}
if (isForbidden(target)) {
context.report(declaration, 'Prop type `' + target + '` is forbidden');
Expand Down

0 comments on commit 9c42ae8

Please sign in to comment.