Skip to content

Commit 9c42ae8

Browse files
committed
Do not modify AST directly (fixes #249)
1 parent 7bbbda7 commit 9c42ae8

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

lib/rules/forbid-prop-types.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,25 @@ module.exports = function(context) {
5454
function checkForbidden(declarations) {
5555
declarations.forEach(function(declaration) {
5656
var target;
57+
var value = declaration.value;
5758
if (
58-
declaration.value.type === 'MemberExpression' &&
59-
declaration.value.property &&
60-
declaration.value.property.name &&
61-
declaration.value.property.name === 'isRequired'
59+
value.type === 'MemberExpression' &&
60+
value.property &&
61+
value.property.name &&
62+
value.property.name === 'isRequired'
6263
) {
63-
declaration.value = declaration.value.object;
64+
value = value.object;
6465
}
6566
if (
66-
declaration.value.type === 'CallExpression' &&
67-
declaration.value.callee.type === 'MemberExpression'
67+
value.type === 'CallExpression' &&
68+
value.callee.type === 'MemberExpression'
6869
) {
69-
declaration.value = declaration.value.callee;
70+
value = value.callee;
7071
}
71-
if (declaration.value.property) {
72-
target = declaration.value.property.name;
73-
} else if (declaration.value.type === 'Identifier') {
74-
target = declaration.value.name;
72+
if (value.property) {
73+
target = value.property.name;
74+
} else if (value.type === 'Identifier') {
75+
target = value.name;
7576
}
7677
if (isForbidden(target)) {
7778
context.report(declaration, 'Prop type `' + target + '` is forbidden');

0 commit comments

Comments
 (0)