@@ -121,6 +121,24 @@ module.exports = {
121121 return false ;
122122 }
123123
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+
124142 /**
125143 * Checks if a prop is being assigned a value props.bar = 'bar'
126144 * @param {ASTNode } node The AST node being checked.
@@ -146,7 +164,7 @@ module.exports = {
146164 node . object . type === 'ThisExpression' && node . property . name === 'props'
147165 ) ;
148166 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 ( ) ) ;
150168 return isClassUsage || isStatelessFunctionUsage || isNextPropsUsage ;
151169 }
152170
@@ -549,7 +567,9 @@ module.exports = {
549567 const isInClassComponent = utils . getParentES6Component ( ) || utils . getParentES5Component ( ) ;
550568 const isNotInConstructor = ! inConstructor ( ) ;
551569 const isNotInComponentWillReceiveProps = ! inComponentWillReceiveProps ( ) ;
552- if ( isDirectProp && isInClassComponent && isNotInConstructor && isNotInComponentWillReceiveProps ) {
570+ const isNotInShouldComponentUpdate = ! inShouldComponentUpdate ( ) ;
571+ if ( isDirectProp && isInClassComponent && isNotInConstructor && isNotInComponentWillReceiveProps
572+ && isNotInShouldComponentUpdate ) {
553573 return void 0 ;
554574 }
555575 if ( ! isDirectProp ) {
@@ -1043,6 +1063,10 @@ module.exports = {
10431063 markPropTypesAsUsed ( node ) ;
10441064 }
10451065
1066+ if ( node . key . name === 'shouldComponentUpdate' && destructuring ) {
1067+ markPropTypesAsUsed ( node ) ;
1068+ }
1069+
10461070 if ( ! node . static || node . kind !== 'get' || ! propsUtil . isPropTypesDeclaration ( node ) ) {
10471071 return ;
10481072 }
0 commit comments