@@ -17,7 +17,7 @@ var annotations = require('../util/annotations');
17
17
// Constants
18
18
// ------------------------------------------------------------------------------
19
19
20
- var DIRECT_PROPS_REGEX = / ^ p r o p s \s * ( \. | \[ ) / ;
20
+ var DIRECT_PROPS_REGEX = / ^ ( p r o p s | n e x t P r o p s ) \s * ( \. | \[ ) / ;
21
21
22
22
// ------------------------------------------------------------------------------
23
23
// Rule Definition
@@ -77,6 +77,24 @@ module.exports = {
77
77
return value ;
78
78
}
79
79
80
+ /**
81
+ * Check if we are in a class constructor
82
+ * @return {boolean } true if we are in a class constructor, false if not
83
+ **/
84
+ function inComponentWillReceiveProps ( ) {
85
+ var scope = context . getScope ( ) ;
86
+ while ( scope ) {
87
+ if (
88
+ scope . block && scope . block . parent &&
89
+ scope . block . parent . key && scope . block . parent . key . name === 'componentWillReceiveProps'
90
+ ) {
91
+ return true ;
92
+ }
93
+ scope = scope . upper ;
94
+ }
95
+ return false ;
96
+ }
97
+
80
98
/**
81
99
* Checks if we are using a prop
82
100
* @param {ASTNode } node The AST node being checked.
@@ -88,7 +106,8 @@ module.exports = {
88
106
node . object . type === 'ThisExpression' && node . property . name === 'props'
89
107
) ;
90
108
var isStatelessFunctionUsage = node . object . name === 'props' ;
91
- return isClassUsage || isStatelessFunctionUsage ;
109
+ var isNextPropsUsage = node . object . name === 'nextProps' && inComponentWillReceiveProps ( ) ;
110
+ return isClassUsage || isStatelessFunctionUsage || isNextPropsUsage ;
92
111
}
93
112
94
113
/**
@@ -493,7 +512,8 @@ module.exports = {
493
512
var isDirectProp = DIRECT_PROPS_REGEX . test ( sourceCode . getText ( node ) ) ;
494
513
var isInClassComponent = utils . getParentES6Component ( ) || utils . getParentES5Component ( ) ;
495
514
var isNotInConstructor = ! inConstructor ( node ) ;
496
- if ( isDirectProp && isInClassComponent && isNotInConstructor ) {
515
+ var isNotInComponentWillReceiveProps = ! inComponentWillReceiveProps ( ) ;
516
+ if ( isDirectProp && isInClassComponent && isNotInConstructor && isNotInComponentWillReceiveProps ) {
497
517
return void 0 ;
498
518
}
499
519
if ( ! isDirectProp ) {
0 commit comments