7
7
8
8
const docsUrl = require ( './docsUrl' ) ;
9
9
const report = require ( './report' ) ;
10
+ const testReactVersion = require ( './version' ) . testReactVersion ;
10
11
11
12
// ------------------------------------------------------------------------------
12
13
// Rule Definition
@@ -29,7 +30,18 @@ const messages = {
29
30
noSetState : 'Do not use setState in {{name}}' ,
30
31
} ;
31
32
32
- function makeNoMethodSetStateRule ( methodName , shouldCheckUnsafeCb ) {
33
+ const methodNoopsAsOf = {
34
+ componentDidMount : '>= 16.3.0' ,
35
+ componentDidUpdate : '>= 16.3.0' ,
36
+ } ;
37
+
38
+ function shouldBeNoop ( context , methodName ) {
39
+ return methodName in methodNoopsAsOf
40
+ && testReactVersion ( context , methodNoopsAsOf [ methodName ] )
41
+ && ! testReactVersion ( context , '999.999.999' ) ; // for when the version is not specified
42
+ }
43
+
44
+ module . exports = function makeNoMethodSetStateRule ( methodName , shouldCheckUnsafeCb ) {
33
45
return {
34
46
meta : {
35
47
docs : {
@@ -67,6 +79,10 @@ function makeNoMethodSetStateRule(methodName, shouldCheckUnsafeCb) {
67
79
68
80
return {
69
81
CallExpression ( node ) {
82
+ if ( shouldBeNoop ( context , methodName ) ) {
83
+ return ;
84
+ }
85
+
70
86
const callee = node . callee ;
71
87
if (
72
88
callee . type !== 'MemberExpression'
@@ -100,6 +116,4 @@ function makeNoMethodSetStateRule(methodName, shouldCheckUnsafeCb) {
100
116
} ;
101
117
} ,
102
118
} ;
103
- }
104
-
105
- module . exports = makeNoMethodSetStateRule ;
119
+ } ;
0 commit comments