@@ -8,7 +8,6 @@ const Components = require('../util/Components');
8
8
const docsUrl = require ( '../util/docsUrl' ) ;
9
9
const isAssignmentLHS = require ( '../util/ast' ) . isAssignmentLHS ;
10
10
const report = require ( '../util/report' ) ;
11
- const testReactVersion = require ( '../util/version' ) . testReactVersion ;
12
11
13
12
const DEFAULT_OPTION = 'always' ;
14
13
@@ -95,8 +94,6 @@ module.exports = {
95
94
const destructureInSignature = ( context . options [ 1 ] && context . options [ 1 ] . destructureInSignature ) || 'ignore' ;
96
95
const sfcParams = createSFCParams ( ) ;
97
96
98
- // set to save renamed var of useContext
99
- const contextSet = new Set ( ) ;
100
97
/**
101
98
* @param {ASTNode } node We expect either an ArrowFunctionExpression,
102
99
* FunctionDeclaration, or FunctionExpression
@@ -131,7 +128,7 @@ module.exports = {
131
128
function handleSFCUsage ( node ) {
132
129
const propsName = sfcParams . propsName ( ) ;
133
130
const contextName = sfcParams . contextName ( ) ;
134
- // props.aProp
131
+ // props.aProp || context.aProp
135
132
const isPropUsed = (
136
133
( propsName && node . object . name === propsName )
137
134
|| ( contextName && node . object . name === contextName )
@@ -145,21 +142,6 @@ module.exports = {
145
142
} ,
146
143
} ) ;
147
144
}
148
-
149
- // const foo = useContext(aContext);
150
- // foo.aProp
151
- const isContextUsed = contextSet . has ( node . object . name ) && ! isAssignmentLHS ( node ) ;
152
- const optional = node . optional
153
- // the below is for the old typescript-eslint parser
154
- || context . getSourceCode ( ) . getText ( node ) . slice ( node . object . range [ 1 ] - node . range [ 0 ] , node . object . range [ 1 ] - node . range [ 0 ] + 1 ) === '?' ;
155
- if ( isContextUsed && configuration === 'always' && ! optional ) {
156
- report ( context , messages . useDestructAssignment , 'useDestructAssignment' , {
157
- node,
158
- data : {
159
- type : node . object . name ,
160
- } ,
161
- } ) ;
162
- }
163
145
}
164
146
165
147
function isInClassProperty ( node ) {
@@ -194,9 +176,8 @@ module.exports = {
194
176
}
195
177
}
196
178
197
- const hasHooks = testReactVersion ( context , '>= 16.9' ) ;
198
-
199
179
return {
180
+
200
181
FunctionDeclaration : handleStatelessComponent ,
201
182
202
183
ArrowFunctionExpression : handleStatelessComponent ,
@@ -231,31 +212,13 @@ module.exports = {
231
212
const SFCComponent = components . get ( context . getScope ( node ) . block ) ;
232
213
233
214
const destructuring = ( node . init && node . id && node . id . type === 'ObjectPattern' ) ;
234
- const identifier = ( node . init && node . id && node . id . type === 'Identifier' ) ;
235
215
// let {foo} = props;
236
- const destructuringSFC = destructuring && node . init . name === 'props' ;
237
- // let {foo} = useContext(aContext);
238
- const destructuringUseContext = hasHooks && destructuring && node . init . callee && node . init . callee . name === 'useContext' ;
239
- // let foo = useContext(aContext);
240
- const assignUseContext = hasHooks && identifier && node . init . callee && node . init . callee . name === 'useContext' ;
216
+ const destructuringSFC = destructuring && ( node . init . name === 'props' || node . init . name === 'context' ) ;
241
217
// let {foo} = this.props;
242
218
const destructuringClass = destructuring && node . init . object && node . init . object . type === 'ThisExpression' && (
243
219
node . init . property . name === 'props' || node . init . property . name === 'context' || node . init . property . name === 'state'
244
220
) ;
245
221
246
- if ( SFCComponent && assignUseContext ) {
247
- contextSet . add ( node . id . name ) ;
248
- }
249
-
250
- if ( SFCComponent && destructuringUseContext && configuration === 'never' ) {
251
- report ( context , messages . noDestructAssignment , 'noDestructAssignment' , {
252
- node,
253
- data : {
254
- type : node . init . callee . name ,
255
- } ,
256
- } ) ;
257
- }
258
-
259
222
if ( SFCComponent && destructuringSFC && configuration === 'never' ) {
260
223
report ( context , messages . noDestructAssignment , 'noDestructAssignment' , {
261
224
node,
0 commit comments