@@ -121,6 +121,24 @@ module.exports = {
121
121
return false ;
122
122
}
123
123
124
+ /**
125
+ * Check if we are in a class constructor
126
+ * @return {boolean } true if we are in a class constructor, false if not
127
+ */
128
+ function inShouldComponentUpdate ( ) {
129
+ let scope = context . getScope ( ) ;
130
+ while ( scope ) {
131
+ if (
132
+ scope . block && scope . block . parent &&
133
+ scope . block . parent . key && scope . block . parent . key . name === 'shouldComponentUpdate'
134
+ ) {
135
+ return true ;
136
+ }
137
+ scope = scope . upper ;
138
+ }
139
+ return false ;
140
+ }
141
+
124
142
/**
125
143
* Checks if a prop is being assigned a value props.bar = 'bar'
126
144
* @param {ASTNode } node The AST node being checked.
@@ -146,7 +164,7 @@ module.exports = {
146
164
node . object . type === 'ThisExpression' && node . property . name === 'props'
147
165
) ;
148
166
const isStatelessFunctionUsage = node . object . name === 'props' && ! isAssignmentToProp ( node ) ;
149
- const isNextPropsUsage = node . object . name === 'nextProps' && inComponentWillReceiveProps ( ) ;
167
+ const isNextPropsUsage = node . object . name === 'nextProps' && ( inComponentWillReceiveProps ( ) || inShouldComponentUpdate ( ) ) ;
150
168
return isClassUsage || isStatelessFunctionUsage || isNextPropsUsage ;
151
169
}
152
170
@@ -549,7 +567,9 @@ module.exports = {
549
567
const isInClassComponent = utils . getParentES6Component ( ) || utils . getParentES5Component ( ) ;
550
568
const isNotInConstructor = ! inConstructor ( ) ;
551
569
const isNotInComponentWillReceiveProps = ! inComponentWillReceiveProps ( ) ;
552
- if ( isDirectProp && isInClassComponent && isNotInConstructor && isNotInComponentWillReceiveProps ) {
570
+ const isNotInShouldComponentUpdate = ! inShouldComponentUpdate ( ) ;
571
+ if ( isDirectProp && isInClassComponent && isNotInConstructor && isNotInComponentWillReceiveProps
572
+ && isNotInShouldComponentUpdate ) {
553
573
return void 0 ;
554
574
}
555
575
if ( ! isDirectProp ) {
@@ -1043,6 +1063,10 @@ module.exports = {
1043
1063
markPropTypesAsUsed ( node ) ;
1044
1064
}
1045
1065
1066
+ if ( node . key . name === 'shouldComponentUpdate' && destructuring ) {
1067
+ markPropTypesAsUsed ( node ) ;
1068
+ }
1069
+
1046
1070
if ( ! node . static || node . kind !== 'get' || ! propsUtil . isPropTypesDeclaration ( node ) ) {
1047
1071
return ;
1048
1072
}
0 commit comments