@@ -8,7 +8,6 @@ const Components = require('../util/Components');
88const docsUrl = require ( '../util/docsUrl' ) ;
99const isAssignmentLHS = require ( '../util/ast' ) . isAssignmentLHS ;
1010const report = require ( '../util/report' ) ;
11- const testReactVersion = require ( '../util/version' ) . testReactVersion ;
1211
1312const DEFAULT_OPTION = 'always' ;
1413
@@ -95,8 +94,6 @@ module.exports = {
9594 const destructureInSignature = ( context . options [ 1 ] && context . options [ 1 ] . destructureInSignature ) || 'ignore' ;
9695 const sfcParams = createSFCParams ( ) ;
9796
98- // set to save renamed var of useContext
99- const contextSet = new Set ( ) ;
10097 /**
10198 * @param {ASTNode } node We expect either an ArrowFunctionExpression,
10299 * FunctionDeclaration, or FunctionExpression
@@ -131,7 +128,7 @@ module.exports = {
131128 function handleSFCUsage ( node ) {
132129 const propsName = sfcParams . propsName ( ) ;
133130 const contextName = sfcParams . contextName ( ) ;
134- // props.aProp
131+ // props.aProp || context.aProp
135132 const isPropUsed = (
136133 ( propsName && node . object . name === propsName )
137134 || ( contextName && node . object . name === contextName )
@@ -145,21 +142,6 @@ module.exports = {
145142 } ,
146143 } ) ;
147144 }
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- }
163145 }
164146
165147 function isInClassProperty ( node ) {
@@ -194,9 +176,8 @@ module.exports = {
194176 }
195177 }
196178
197- const hasHooks = testReactVersion ( context , '>= 16.9' ) ;
198-
199179 return {
180+
200181 FunctionDeclaration : handleStatelessComponent ,
201182
202183 ArrowFunctionExpression : handleStatelessComponent ,
@@ -231,31 +212,13 @@ module.exports = {
231212 const SFCComponent = components . get ( context . getScope ( node ) . block ) ;
232213
233214 const destructuring = ( node . init && node . id && node . id . type === 'ObjectPattern' ) ;
234- const identifier = ( node . init && node . id && node . id . type === 'Identifier' ) ;
235215 // 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' ) ;
241217 // let {foo} = this.props;
242218 const destructuringClass = destructuring && node . init . object && node . init . object . type === 'ThisExpression' && (
243219 node . init . property . name === 'props' || node . init . property . name === 'context' || node . init . property . name === 'state'
244220 ) ;
245221
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-
259222 if ( SFCComponent && destructuringSFC && configuration === 'never' ) {
260223 report ( context , messages . noDestructAssignment , 'noDestructAssignment' , {
261224 node,
0 commit comments