Changeset 0c6b92a for imaps-frontend/node_modules/eslint-plugin-react/lib/rules/destructuring-assignment.js
Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/eslint-plugin-react/lib/rules/destructuring-assignment.js
rd565449 r0c6b92a 182 182 } 183 183 184 // valid-jsdoc cannot read function types 185 // eslint-disable-next-line valid-jsdoc 186 /** 187 * Find a parent that satisfy the given predicate 188 * @param {ASTNode} node 189 * @param {(node: ASTNode) => boolean} predicate 190 * @returns {ASTNode | undefined} 191 */ 192 function findParent(node, predicate) { 193 let n = node; 194 while (n) { 195 if (predicate(n)) { 196 return n; 197 } 198 n = n.parent; 199 } 200 return undefined; 201 } 202 184 203 return { 185 204 … … 197 216 198 217 MemberExpression(node) { 199 let scope = getScope(context, node); 200 let SFCComponent = components.get(scope.block); 201 while (!SFCComponent && scope.upper && scope.upper !== scope) { 202 SFCComponent = components.get(scope.upper.block); 203 scope = scope.upper; 204 } 218 const SFCComponent = utils.getParentStatelessComponent(node); 205 219 if (SFCComponent) { 206 220 handleSFCUsage(node); … … 210 224 if (classComponent) { 211 225 handleClassUsage(node); 226 } 227 }, 228 229 TSQualifiedName(node) { 230 if (configuration !== 'always') { 231 return; 232 } 233 // handle `typeof props.a.b` 234 if (node.left.type === 'Identifier' 235 && node.left.name === sfcParams.propsName() 236 && findParent(node, (n) => n.type === 'TSTypeQuery') 237 && utils.getParentStatelessComponent(node) 238 ) { 239 report(context, messages.useDestructAssignment, 'useDestructAssignment', { 240 node, 241 data: { 242 type: 'props', 243 }, 244 }); 212 245 } 213 246 }, … … 258 291 return; 259 292 } 293 260 294 // Skip if props is used elsewhere 261 295 if (propsRefs.length > 1) {
Note:
See TracChangeset
for help on using the changeset viewer.