@@ -52,7 +52,7 @@ module.exports = {
52
52
create : Components . detect ( ( context , components , utils ) => {
53
53
const config = context . options [ 0 ] || { } ;
54
54
const ignoreTranspilerName = config . ignoreTranspilerName || false ;
55
- const checkContextObjects = config . checkContextObjects || false ;
55
+ const checkContextObjects = ( config . checkContextObjects || false ) && testReactVersion ( context , '>= 16.3.0' ) ;
56
56
57
57
const contextObjects = new Map ( ) ;
58
58
@@ -78,28 +78,28 @@ module.exports = {
78
78
}
79
79
80
80
/**
81
- * Checks if the node is a createContext call
81
+ * Checks if the node is a React. createContext call
82
82
* @param {ASTNode } node - The AST node being checked.
83
- * @returns {Boolean } - True if node is a createContext call object literal, False if not.
83
+ * @returns {Boolean } - True if node is a React. createContext call object literal, false if not.
84
84
*/
85
85
function isCreateContext ( node ) {
86
86
if ( ! node . init ) {
87
87
return false ;
88
88
}
89
89
90
90
if (
91
- node . init . type === 'CallExpression' &&
92
- node . init . callee &&
93
- node . init . callee . name === 'createContext'
91
+ node . init . type === 'CallExpression'
92
+ && node . init . callee
93
+ && node . init . callee . name === 'createContext'
94
94
) {
95
95
return true ;
96
96
}
97
97
98
98
if (
99
- node . init . callee &&
100
- node . init . callee . type === 'MemberExpression' &&
101
- node . init . callee . property &&
102
- node . init . callee . property . name === 'createContext'
99
+ node . init . callee
100
+ && node . init . callee . type === 'MemberExpression'
101
+ && node . init . callee . property
102
+ && node . init . callee . property . name === 'createContext'
103
103
) {
104
104
return true ;
105
105
}
@@ -129,11 +129,9 @@ module.exports = {
129
129
* @param {Object } contextObj The context object to process
130
130
*/
131
131
function reportMissingContextDisplayName ( contextObj ) {
132
- if ( testReactVersion ( context , '>= 16.3.0' ) ) {
133
- report ( context , messages . noContextDisplayName , 'noContextDisplayName' , {
134
- node : contextObj . node ,
135
- } ) ;
136
- }
132
+ report ( context , messages . noContextDisplayName , 'noContextDisplayName' , {
133
+ node : contextObj . node ,
134
+ } ) ;
137
135
}
138
136
139
137
/**
@@ -210,10 +208,10 @@ module.exports = {
210
208
return ;
211
209
}
212
210
if (
213
- checkContextObjects &&
214
- node . object &&
215
- node . object . name &&
216
- contextObjects . has ( node . object . name )
211
+ checkContextObjects
212
+ && node . object
213
+ && node . object . name
214
+ && contextObjects . has ( node . object . name )
217
215
) {
218
216
contextObjects . get ( node . object . name ) . hasDisplayName = true ;
219
217
}
0 commit comments