@@ -16,8 +16,10 @@ var annotations = require('../util/annotations');
16
16
// Constants
17
17
// ------------------------------------------------------------------------------
18
18
19
- var DIRECT_PROPS_REGEX = / ^ p r o p s \s * ( \. | \[ ) / ;
20
- var DIRECT_NEXT_PROPS_REGEX = / ^ n e x t P r o p s \s * ( \. | \[ ) / ;
19
+ const DIRECT_PROPS_REGEX = / ^ p r o p s \s * ( \. | \[ ) / ;
20
+ const DIRECT_NEXT_PROPS_REGEX = / ^ n e x t P r o p s \s * ( \. | \[ ) / ;
21
+ const DIRECT_PREV_PROPS_REGEX = / ^ p r e v P r o p s \s * ( \. | \[ ) / ;
22
+ const LIFE_CYCLE_METHODS = [ 'componentWillReceiveProps' , 'shouldComponentUpdate' , 'componentWillUpdate' , 'componentDidUpdate' ] ;
21
23
22
24
// ------------------------------------------------------------------------------
23
25
// Rule Definition
@@ -78,15 +80,16 @@ module.exports = {
78
80
}
79
81
80
82
/**
81
- * Check if we are in a class constructor
83
+ * Check if we are in a lifecycle method
82
84
* @return {boolean } true if we are in a class constructor, false if not
83
85
**/
84
- function inComponentWillReceiveProps ( ) {
86
+ function inLifeCycleMethod ( ) {
85
87
var scope = context . getScope ( ) ;
86
88
while ( scope ) {
87
89
if (
88
90
scope . block && scope . block . parent &&
89
- scope . block . parent . key && scope . block . parent . key . name === 'componentWillReceiveProps'
91
+ scope . block . parent . key &&
92
+ LIFE_CYCLE_METHODS . indexOf ( scope . block . parent . key . name ) >= 0
90
93
) {
91
94
return true ;
92
95
}
@@ -106,8 +109,7 @@ module.exports = {
106
109
node . object . type === 'ThisExpression' && node . property . name === 'props'
107
110
) ;
108
111
var isStatelessFunctionUsage = node . object . name === 'props' ;
109
- var isNextPropsUsage = node . object . name === 'nextProps' && inComponentWillReceiveProps ( ) ;
110
- return isClassUsage || isStatelessFunctionUsage || isNextPropsUsage ;
112
+ return isClassUsage || isStatelessFunctionUsage || inLifeCycleMethod ( ) ;
111
113
}
112
114
113
115
/**
@@ -511,16 +513,17 @@ module.exports = {
511
513
function getPropertyName ( node ) {
512
514
var isDirectProp = DIRECT_PROPS_REGEX . test ( sourceCode . getText ( node ) ) ;
513
515
var isDirectNextProp = DIRECT_NEXT_PROPS_REGEX . test ( sourceCode . getText ( node ) ) ;
516
+ var isDirectPrevProp = DIRECT_PREV_PROPS_REGEX . test ( sourceCode . getText ( node ) ) ;
514
517
var isInClassComponent = utils . getParentES6Component ( ) || utils . getParentES5Component ( ) ;
515
518
var isNotInConstructor = ! inConstructor ( node ) ;
516
- var isNotInComponentWillReceiveProps = ! inComponentWillReceiveProps ( ) ;
517
- if ( ( isDirectProp || isDirectNextProp )
519
+ var isNotInLifeCycleMethod = ! inLifeCycleMethod ( ) ;
520
+ if ( ( isDirectProp || isDirectNextProp || isDirectPrevProp )
518
521
&& isInClassComponent
519
522
&& isNotInConstructor
520
- && isNotInComponentWillReceiveProps ) {
523
+ && isNotInLifeCycleMethod ) {
521
524
return void 0 ;
522
525
}
523
- if ( ! isDirectProp && ! isDirectNextProp ) {
526
+ if ( ! isDirectProp && ! isDirectNextProp && ! isDirectPrevProp ) {
524
527
node = node . parent ;
525
528
}
526
529
var property = node . property ;
0 commit comments