- Timestamp:
- 12/12/24 17:06:06 (5 weeks ago)
- Branches:
- main
- Parents:
- d565449
- Location:
- imaps-frontend/node_modules/eslint-plugin-react/lib/util
- Files:
-
- 56 added
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/eslint-plugin-react/lib/util/Components.js
rd565449 r0c6b92a 71 71 * 72 72 * @param {ASTNode} node The AST node being added. 73 * @param { Number} confidence Confidence in the component detection (0=banned, 1=maybe, 2=yes)73 * @param {number} confidence Confidence in the component detection (0=banned, 1=maybe, 2=yes) 74 74 * @returns {Object} Added component object 75 75 */ … … 184 184 * Components for which we are not confident are not counted 185 185 * 186 * @returns { Number} Components list length186 * @returns {number} Components list length 187 187 */ 188 188 length() { … … 304 304 305 305 /** 306 * @param {ASTNode} ASTNode306 * @param {ASTNode} node 307 307 * @param {boolean=} strict 308 308 * @returns {boolean} 309 309 */ 310 isReturningJSX( ASTNode, strict) {311 return jsxUtil.isReturningJSX(context, ASTNode, strict, true);312 }, 313 314 isReturningJSXOrNull( ASTNode, strict) {315 return jsxUtil.isReturningJSX(context, ASTNode, strict);316 }, 317 318 isReturningOnlyNull( ASTNode) {319 return jsxUtil.isReturningOnlyNull( ASTNode, context);310 isReturningJSX(node, strict) { 311 return jsxUtil.isReturningJSX(context, node, strict, true); 312 }, 313 314 isReturningJSXOrNull(node, strict) { 315 return jsxUtil.isReturningJSX(context, node, strict); 316 }, 317 318 isReturningOnlyNull(node) { 319 return jsxUtil.isReturningOnlyNull(node, context); 320 320 }, 321 321 … … 408 408 409 409 isPragmaComponentWrapper(node) { 410 if (! node || node.type !== 'CallExpression') {410 if (!astUtil.isCallExpression(node)) { 411 411 return false; 412 412 } … … 568 568 569 569 // for case abc = { [someobject.somekey]: props => { ... return not-jsx } } 570 if (node.parent && node.parent.key && node.parent.key.type === 'MemberExpression' && !utils.isReturningJSX(node) && !utils.isReturningOnlyNull(node)) { 570 if ( 571 node.parent 572 && node.parent.key 573 && node.parent.key.type === 'MemberExpression' 574 && !utils.isReturningJSX(node) 575 && !utils.isReturningOnlyNull(node) 576 ) { 571 577 return undefined; 572 578 } … … 578 584 ) 579 585 ) { 580 if (isFirstLetterCapitalized(node.parent.key.name) && utils.isReturningJSX(node)) { 586 if ( 587 isFirstLetterCapitalized(node.parent.key.name) 588 && utils.isReturningJSX(node) 589 ) { 581 590 return node; 582 591 } … … 642 651 * 643 652 * @param {ASTNode} node The AST node being checked (must be a MemberExpression). 644 * @returns {ASTNode } component node, null if we cannot find the component653 * @returns {ASTNode | null} component node, null if we cannot find the component 645 654 */ 646 655 getRelatedComponent(node) { … … 752 761 * @param {ASTNode} node The AST node being searched. (expects CallExpression) 753 762 * @param {('useCallback'|'useContext'|'useDebugValue'|'useEffect'|'useImperativeHandle'|'useLayoutEffect'|'useMemo'|'useReducer'|'useRef'|'useState')[]} [expectedHookNames] React hook names to which search is limited. 754 * @returns { Boolean} True if the node is a call to a React hook763 * @returns {boolean} True if the node is a call to a React hook 755 764 */ 756 765 isReactHookCall(node, expectedHookNames) { 757 if ( node.type !== 'CallExpression') {766 if (!astUtil.isCallExpression(node)) { 758 767 return false; 759 768 } … … 799 808 800 809 const hookResolvedDefs = potentialHookReference && potentialHookReference.resolved.defs; 801 const localHookName = (isPotentialReactHookCall && node.callee.property.name) 802 || (isPotentialHookCall && potentialHookReference && node.callee.name); 810 const localHookName = ( 811 isPotentialReactHookCall 812 && node.callee.property.name 813 ) || ( 814 isPotentialHookCall 815 && potentialHookReference 816 && node.callee.name 817 ); 803 818 const isHookShadowed = isPotentialHookCall 804 819 && hookResolvedDefs … … 877 892 } 878 893 879 node = utils.getStatelessComponent(node);880 if (! node) {881 return; 882 } 883 components.add( node, 2);894 const cNode = utils.getStatelessComponent(node); 895 if (!cNode) { 896 return; 897 } 898 components.add(cNode, 2); 884 899 }, 885 900 -
imaps-frontend/node_modules/eslint-plugin-react/lib/util/annotations.js
rd565449 r0c6b92a 13 13 * @param {ASTNode} node The AST node being checked. 14 14 * @param {Object} context 15 * @returns { Boolean} True if the node is a type annotated props declaration, false if not.15 * @returns {boolean} True if the node is a type annotated props declaration, false if not. 16 16 */ 17 17 function isAnnotatedFunctionPropsDeclaration(node, context) { -
imaps-frontend/node_modules/eslint-plugin-react/lib/util/ast.js
rd565449 r0c6b92a 93 93 94 94 /* TODO: properly warn on React.forwardRefs having typo properties 95 if ( nodeType === 'CallExpression') {95 if (astUtil.isCallExpression(ASTNode)) { 96 96 const callee = ASTNode.callee; 97 97 const pragma = pragmaUtil.getFromContext(context); … … 149 149 */ 150 150 function getPropertyNameNode(node) { 151 if (node.key || ['MethodDefinition', 'Property'].indexOf(node.type) !== -1) { 151 if ( 152 node.key 153 || node.type === 'MethodDefinition' 154 || node.type === 'Property' 155 ) { 152 156 return node.key; 153 157 } … … 161 165 * Get properties name 162 166 * @param {Object} node - Property. 163 * @returns { String} Property name.167 * @returns {string} Property name. 164 168 */ 165 169 function getPropertyName(node) { … … 211 215 * @param {Object} context The node to check 212 216 * @param {ASTNode} node The node to check 213 * @return { Boolean} true if it's the first node in its line217 * @return {boolean} true if it's the first node in its line 214 218 */ 215 219 function isNodeFirstInLine(context, node) { … … 223 227 * Checks if the node is a function or arrow function expression. 224 228 * @param {ASTNode} node The node to check 225 * @return { Boolean} true if it's a function-like expression229 * @return {boolean} true if it's a function-like expression 226 230 */ 227 231 function isFunctionLikeExpression(node) { … … 232 236 * Checks if the node is a function. 233 237 * @param {ASTNode} node The node to check 234 * @return { Boolean} true if it's a function238 * @return {boolean} true if it's a function 235 239 */ 236 240 function isFunction(node) { … … 241 245 * Checks if node is a function declaration or expression or arrow function. 242 246 * @param {ASTNode} node The node to check 243 * @return { Boolean} true if it's a function-like247 * @return {boolean} true if it's a function-like 244 248 */ 245 249 function isFunctionLike(node) { … … 250 254 * Checks if the node is a class. 251 255 * @param {ASTNode} node The node to check 252 * @return { Boolean} true if it's a class256 * @return {boolean} true if it's a class 253 257 */ 254 258 function isClass(node) { … … 330 334 * Checks if a node is being assigned a value: props.bar = 'bar' 331 335 * @param {ASTNode} node The AST node being checked. 332 * @returns { Boolean}336 * @returns {boolean} 333 337 */ 334 338 function isAssignmentLHS(node) { … … 340 344 } 341 345 346 function isTSAsExpression(node) { 347 return node && node.type === 'TSAsExpression'; 348 } 349 350 /** 351 * Matcher used to check whether given node is a `CallExpression` 352 * @param {ASTNode} node The AST node 353 * @returns {boolean} True if node is a `CallExpression`, false if not 354 */ 355 function isCallExpression(node) { 356 return node && node.type === 'CallExpression'; 357 } 358 342 359 /** 343 360 * Extracts the expression node that is wrapped inside a TS type assertion … … 347 364 */ 348 365 function unwrapTSAsExpression(node) { 349 if (node && node.type === 'TSAsExpression') return node.expression; 350 return node; 366 return isTSAsExpression(node) ? node.expression : node; 351 367 } 352 368 353 369 function isTSTypeReference(node) { 354 370 if (!node) return false; 355 const nodeType = node.type; 356 return node Type === 'TSTypeReference';371 372 return node.type === 'TSTypeReference'; 357 373 } 358 374 359 375 function isTSTypeAnnotation(node) { 360 if (!node) return false;361 const nodeType = node.type; 362 return node Type === 'TSTypeAnnotation';376 if (!node) { return false; } 377 378 return node.type === 'TSTypeAnnotation'; 363 379 } 364 380 365 381 function isTSTypeLiteral(node) { 366 if (!node) return false;367 const nodeType = node.type; 368 return node Type === 'TSTypeLiteral';382 if (!node) { return false; } 383 384 return node.type === 'TSTypeLiteral'; 369 385 } 370 386 371 387 function isTSIntersectionType(node) { 372 if (!node) return false;373 const nodeType = node.type; 374 return node Type === 'TSIntersectionType';388 if (!node) { return false; } 389 390 return node.type === 'TSIntersectionType'; 375 391 } 376 392 377 393 function isTSInterfaceHeritage(node) { 378 if (!node) return false;379 const nodeType = node.type; 380 return node Type === 'TSInterfaceHeritage';394 if (!node) { return false; } 395 396 return node.type === 'TSInterfaceHeritage'; 381 397 } 382 398 383 399 function isTSInterfaceDeclaration(node) { 384 if (!node) return false; 385 let nodeType = node.type; 400 if (!node) { return false; } 401 402 return (node.type === 'ExportNamedDeclaration' && node.declaration 403 ? node.declaration.type 404 : node.type 405 ) === 'TSInterfaceDeclaration'; 406 } 407 408 function isTSTypeDeclaration(node) { 409 if (!node) { return false; } 410 411 const nodeToCheck = node.type === 'ExportNamedDeclaration' && node.declaration 412 ? node.declaration 413 : node; 414 415 return nodeToCheck.type === 'VariableDeclaration' && nodeToCheck.kind === 'type'; 416 } 417 418 function isTSTypeAliasDeclaration(node) { 419 if (!node) { return false; } 420 386 421 if (node.type === 'ExportNamedDeclaration' && node.declaration) { 387 nodeType = node.declaration.type; 388 } 389 return nodeType === 'TSInterfaceDeclaration'; 390 } 391 392 function isTSTypeDeclaration(node) { 393 if (!node) return false; 394 let nodeType = node.type; 395 let nodeKind = node.kind; 396 if (node.type === 'ExportNamedDeclaration' && node.declaration) { 397 nodeType = node.declaration.type; 398 nodeKind = node.declaration.kind; 399 } 400 return nodeType === 'VariableDeclaration' && nodeKind === 'type'; 401 } 402 403 function isTSTypeAliasDeclaration(node) { 404 if (!node) return false; 405 let nodeType = node.type; 406 if (node.type === 'ExportNamedDeclaration' && node.declaration) { 407 nodeType = node.declaration.type; 408 return nodeType === 'TSTypeAliasDeclaration' && node.exportKind === 'type'; 409 } 410 return nodeType === 'TSTypeAliasDeclaration'; 422 return node.declaration.type === 'TSTypeAliasDeclaration' && node.exportKind === 'type'; 423 } 424 return node.type === 'TSTypeAliasDeclaration'; 411 425 } 412 426 413 427 function isTSParenthesizedType(node) { 414 if (!node) return false;415 const nodeType = node.type; 416 return node Type === 'TSTypeAliasDeclaration';428 if (!node) { return false; } 429 430 return node.type === 'TSTypeAliasDeclaration'; 417 431 } 418 432 419 433 function isTSFunctionType(node) { 420 if (!node) return false;421 const nodeType = node.type; 422 return node Type === 'TSFunctionType';434 if (!node) { return false; } 435 436 return node.type === 'TSFunctionType'; 423 437 } 424 438 425 439 function isTSTypeQuery(node) { 426 if (!node) return false;427 const nodeType = node.type; 428 return node Type === 'TSTypeQuery';440 if (!node) { return false; } 441 442 return node.type === 'TSTypeQuery'; 429 443 } 430 444 431 445 function isTSTypeParameterInstantiation(node) { 432 if (!node) return false;433 const nodeType = node.type; 434 return node Type === 'TSTypeParameterInstantiation';446 if (!node) { return false; } 447 448 return node.type === 'TSTypeParameterInstantiation'; 435 449 } 436 450 437 451 module.exports = { 438 traverse,439 452 findReturnStatement, 453 getComponentProperties, 440 454 getFirstNodeInLine, 455 getKeyValue, 441 456 getPropertyName, 442 457 getPropertyNameNode, 443 getComponentProperties, 444 getKeyValue, 445 isParenthesized, 458 inConstructor, 446 459 isAssignmentLHS, 460 isCallExpression, 447 461 isClass, 448 462 isFunction, 463 isFunctionLike, 449 464 isFunctionLikeExpression, 450 isFunctionLike,451 inConstructor,452 465 isNodeFirstInLine, 466 isParenthesized, 467 isTSAsExpression, 468 isTSFunctionType, 469 isTSInterfaceDeclaration, 470 isTSInterfaceHeritage, 471 isTSIntersectionType, 472 isTSParenthesizedType, 473 isTSTypeAliasDeclaration, 474 isTSTypeAnnotation, 475 isTSTypeDeclaration, 476 isTSTypeLiteral, 477 isTSTypeParameterInstantiation, 478 isTSTypeQuery, 479 isTSTypeReference, 480 traverse, 481 traverseReturns, 453 482 unwrapTSAsExpression, 454 traverseReturns,455 isTSTypeReference,456 isTSTypeAnnotation,457 isTSTypeLiteral,458 isTSIntersectionType,459 isTSInterfaceHeritage,460 isTSInterfaceDeclaration,461 isTSTypeAliasDeclaration,462 isTSParenthesizedType,463 isTSFunctionType,464 isTSTypeQuery,465 isTSTypeParameterInstantiation,466 isTSTypeDeclaration,467 483 }; -
imaps-frontend/node_modules/eslint-plugin-react/lib/util/componentUtil.js
rd565449 r0c6b92a 175 175 */ 176 176 function isStateMemberExpression(node) { 177 return node.type === 'MemberExpression' && node.object.type === 'ThisExpression' && node.property.name === 'state'; 177 return node.type === 'MemberExpression' 178 && node.object.type === 'ThisExpression' 179 && node.property.name === 'state'; 178 180 } 179 181 -
imaps-frontend/node_modules/eslint-plugin-react/lib/util/defaultProps.js
rd565449 r0c6b92a 27 27 } 28 28 if ( 29 node.type === 'CallExpression'29 astUtil.isCallExpression(node) 30 30 && propWrapperUtil.isPropWrapperFunction(context, node.callee.name) 31 31 && node.arguments && node.arguments[0] -
imaps-frontend/node_modules/eslint-plugin-react/lib/util/error.js
rd565449 r0c6b92a 3 3 /** 4 4 * Logs out a message if there is no format option set. 5 * @param { String} message - Message to log.5 * @param {string} message - Message to log. 6 6 */ 7 7 function error(message) { -
imaps-frontend/node_modules/eslint-plugin-react/lib/util/isCreateContext.js
rd565449 r0c6b92a 1 1 'use strict'; 2 3 const astUtil = require('./ast'); 2 4 3 5 /** 4 6 * Checks if the node is a React.createContext call 5 7 * @param {ASTNode} node - The AST node being checked. 6 * @returns { Boolean} - True if node is a React.createContext call, false if not.8 * @returns {boolean} - True if node is a React.createContext call, false if not. 7 9 */ 8 10 module.exports = function isCreateContext(node) { 9 11 if ( 10 12 node.init 11 && node.init.type === 'CallExpression'12 13 && node.init.callee 13 && node.init.callee.name === 'createContext'14 14 ) { 15 return true; 16 } 15 if ( 16 astUtil.isCallExpression(node.init) 17 && node.init.callee.name === 'createContext' 18 ) { 19 return true; 20 } 17 21 18 if ( 19 node.init 20 && node.init.callee 21 && node.init.callee.type === 'MemberExpression' 22 && node.init.callee.property 23 && node.init.callee.property.name === 'createContext' 24 ) { 25 return true; 22 if ( 23 node.init.callee.type === 'MemberExpression' 24 && node.init.callee.property 25 && node.init.callee.property.name === 'createContext' 26 ) { 27 return true; 28 } 26 29 } 27 30 … … 30 33 && node.expression.type === 'AssignmentExpression' 31 34 && node.expression.operator === '=' 32 && node.expression.right.type === 'CallExpression'35 && astUtil.isCallExpression(node.expression.right) 33 36 && node.expression.right.callee 34 && node.expression.right.callee.name === 'createContext'35 37 ) { 36 return true; 37 } 38 const right = node.expression.right; 38 39 39 if (40 node.expression41 && node.expression.type === 'AssignmentExpression'42 && node.expression.operator === '=' 43 && node.expression.right.type === 'CallExpression'44 && node.expression.right.callee45 && node.expression.right.callee.type === 'MemberExpression'46 && node.expression.right.callee.property47 && node.expression.right.callee.property.name === 'createContext'48 ) {49 return true;40 if (right.callee.name === 'createContext') { 41 return true; 42 } 43 44 if ( 45 right.callee.type === 'MemberExpression' 46 && right.callee.property 47 && right.callee.property.name === 'createContext' 48 ) { 49 return true; 50 } 50 51 } 51 52 -
imaps-frontend/node_modules/eslint-plugin-react/lib/util/isCreateElement.js
rd565449 r0c6b92a 11 11 */ 12 12 module.exports = function isCreateElement(context, node) { 13 if (!node.callee) { 14 return false; 15 } 16 13 17 if ( 14 node.callee 15 && node.callee.type === 'MemberExpression' 18 node.callee.type === 'MemberExpression' 16 19 && node.callee.property.name === 'createElement' 17 20 && node.callee.object … … 22 25 23 26 if ( 24 node 25 && node.callee 26 && node.callee.name === 'createElement' 27 node.callee.name === 'createElement' 27 28 && isDestructuredFromPragmaImport(context, node, 'createElement') 28 29 ) { -
imaps-frontend/node_modules/eslint-plugin-react/lib/util/isDestructuredFromPragmaImport.js
rd565449 r0c6b92a 1 1 'use strict'; 2 2 3 const astUtil = require('./ast'); 3 4 const pragmaUtil = require('./pragma'); 4 5 const variableUtil = require('./variable'); … … 23 24 if ( 24 25 latestDef.node.init.type === 'MemberExpression' 25 26 26 && latestDef.node.init.object.type === 'Identifier' 27 && latestDef.node.init.object.name === pragma 27 28 ) { 28 29 return true; … … 31 32 if ( 32 33 latestDef.node.init.type === 'Identifier' 33 34 && latestDef.node.init.name === pragma 34 35 ) { 35 36 return true; … … 40 41 41 42 // get "require('react')" from: "{variable} = require('react')" 42 if ( latestDef.node.init.type === 'CallExpression') {43 if (astUtil.isCallExpression(latestDef.node.init)) { 43 44 requireExpression = latestDef.node.init; 44 45 } … … 46 47 if ( 47 48 !requireExpression 48 49 && latestDef.node.init.object.type === 'CallExpression'49 && latestDef.node.init.type === 'MemberExpression' 50 && astUtil.isCallExpression(latestDef.node.init.object) 50 51 ) { 51 52 requireExpression = latestDef.node.init.object; … … 55 56 if ( 56 57 requireExpression 57 58 59 60 58 && requireExpression.callee 59 && requireExpression.callee.name === 'require' 60 && requireExpression.arguments[0] 61 && requireExpression.arguments[0].value === pragma.toLocaleLowerCase() 61 62 ) { 62 63 return true; … … 69 70 if ( 70 71 latestDef.parent 71 72 72 && latestDef.parent.type === 'ImportDeclaration' 73 && latestDef.parent.source.value === pragma.toLocaleLowerCase() 73 74 ) { 74 75 return true; -
imaps-frontend/node_modules/eslint-plugin-react/lib/util/isFirstLetterCapitalized.js
rd565449 r0c6b92a 3 3 /** 4 4 * Check if the first letter of a string is capitalized. 5 * @param { String} word String to check6 * @returns { Boolean} True if first letter is capitalized.5 * @param {string} word String to check 6 * @returns {boolean} True if first letter is capitalized. 7 7 */ 8 function isFirstLetterCapitalized(word) {8 module.exports = function isFirstLetterCapitalized(word) { 9 9 if (!word) { 10 10 return false; … … 12 12 const firstLetter = word.replace(/^_+/, '').charAt(0); 13 13 return firstLetter.toUpperCase() === firstLetter; 14 } 15 16 module.exports = isFirstLetterCapitalized; 14 }; -
imaps-frontend/node_modules/eslint-plugin-react/lib/util/jsx.js
rd565449 r0c6b92a 77 77 /** 78 78 * Check if value has only whitespaces 79 * @param { string} value79 * @param {unknown} value 80 80 * @returns {boolean} 81 81 */ … … 89 89 * @param {Context} context The context of `ASTNode`. 90 90 * @param {ASTNode} ASTnode The AST node being checked 91 * @param { Boolean} [strict] If true, in a ternary condition the node must return JSX in both cases92 * @param { Boolean} [ignoreNull] If true, null return values will be ignored93 * @returns { Boolean} True if the node is returning JSX or null, false if not91 * @param {boolean} [strict] If true, in a ternary condition the node must return JSX in both cases 92 * @param {boolean} [ignoreNull] If true, null return values will be ignored 93 * @returns {boolean} True if the node is returning JSX or null, false if not 94 94 */ 95 95 function isReturningJSX(context, ASTnode, strict, ignoreNull) { … … 146 146 * @param {ASTNode} ASTnode The AST node being checked 147 147 * @param {Context} context The context of `ASTNode`. 148 * @returns { Boolean} True if the node is returning only null values148 * @returns {boolean} True if the node is returning only null values 149 149 */ 150 150 function isReturningOnlyNull(ASTnode, context) { -
imaps-frontend/node_modules/eslint-plugin-react/lib/util/log.js
rd565449 r0c6b92a 3 3 /** 4 4 * Logs out a message if there is no format option set. 5 * @param { String} message - Message to log.5 * @param {string} message - Message to log. 6 6 */ 7 7 function log(message) { -
imaps-frontend/node_modules/eslint-plugin-react/lib/util/makeNoMethodSetStateRule.js
rd565449 r0c6b92a 45 45 } 46 46 47 // eslint-disable-next-line valid-jsdoc 48 /** 49 * @param {string} methodName 50 * @param {(context: import('eslint').Rule.RuleContext) => boolean} [shouldCheckUnsafeCb] 51 * @returns {import('eslint').Rule.RuleModule} 52 */ 47 53 module.exports = function makeNoMethodSetStateRule(methodName, shouldCheckUnsafeCb) { 48 54 return { … … 91 97 callee.type !== 'MemberExpression' 92 98 || callee.object.type !== 'ThisExpression' 99 || !('name' in callee.property) 93 100 || callee.property.name !== 'setState' 94 101 ) { -
imaps-frontend/node_modules/eslint-plugin-react/lib/util/pragma.js
rd565449 r0c6b92a 63 63 64 64 if (!JS_IDENTIFIER_REGEX.test(pragma)) { 65 throw new Error(`React pragma ${pragma} is not a valid identifier`); 65 console.warn(`React pragma ${pragma} is not a valid identifier`); 66 return 'React'; 66 67 } 67 68 return pragma; -
imaps-frontend/node_modules/eslint-plugin-react/lib/util/propTypes.js
rd565449 r0c6b92a 24 24 * Check if node is function type. 25 25 * @param {ASTNode} node 26 * @returns { Boolean}26 * @returns {boolean} 27 27 */ 28 28 function isFunctionType(node) { … … 38 38 * 39 39 * @param {ASTNode} node the AST node being checked. 40 * @returns { Boolean} True if the node is a class with generic prop types, false if not.40 * @returns {boolean} True if the node is a class with generic prop types, false if not. 41 41 */ 42 42 function isSuperTypeParameterPropsDeclaration(node) { 43 43 if (node && (node.type === 'ClassDeclaration' || node.type === 'ClassExpression')) { 44 if (node.superTypeParameters && node.superTypeParameters.params.length > 0) { 44 const parameters = propsUtil.getSuperTypeArguments(node); 45 if (parameters && parameters.params.length > 0) { 45 46 return true; 46 47 } … … 77 78 * Checks if a node is inside a class body. 78 79 * 79 * @param {ASTNode} node 80 * @returns { Boolean} True if the node has a ClassBody ancestor, false if not.80 * @param {ASTNode} node the AST node being checked. 81 * @returns {boolean} True if the node has a ClassBody ancestor, false if not. 81 82 */ 82 83 function isInsideClassBody(node) { … … 153 154 /** 154 155 * Checks if prop should be validated by plugin-react-proptypes 155 * @param { String} validator Name of validator to check.156 * @returns { Boolean} True if validator should be checked by custom validator.156 * @param {string} validator Name of validator to check. 157 * @returns {boolean} True if validator should be checked by custom validator. 157 158 */ 158 159 function hasCustomValidator(validator) { … … 173 174 let containsUnresolvedObjectTypeSpread = false; 174 175 let containsSpread = false; 175 const containsIndexers = Boolean(annotation.indexers && annotation.indexers.length);176 const containsIndexers = !!annotation.indexers && annotation.indexers.length > 0; 176 177 const shapeTypeDefinition = { 177 178 type: 'shape', … … 268 269 * The representation is used to verify nested used properties. 269 270 * @param {ASTNode} annotation Type annotation for the props class property. 270 * @param { String} parentName271 * @param {string} parentName 271 272 * @param {Set<ASTNode>} [seen] 272 273 * @return {Object} The representation of the declaration, empty object means … … 297 298 * @param {ASTNode} propTypes 298 299 * @param {Object} declaredPropTypes 299 * @returns { Boolean} True if propTypes should be ignored (e.g. when a type can't be resolved, when it is imported)300 * @returns {boolean} True if propTypes should be ignored (e.g. when a type can't be resolved, when it is imported) 300 301 */ 301 302 function declarePropTypesForObjectTypeAnnotation(propTypes, declaredPropTypes) { … … 335 336 * @param {ASTNode} propTypes 336 337 * @param {Object} declaredPropTypes 337 * @returns { Boolean} True if propTypes should be ignored (e.g. when a type can't be resolved, when it is imported)338 * @returns {boolean} True if propTypes should be ignored (e.g. when a type can't be resolved, when it is imported) 338 339 */ 339 340 function declarePropTypesForIntersectionTypeAnnotation(propTypes, declaredPropTypes) { … … 428 429 && value.type === 'MemberExpression' 429 430 && value.property 430 && value.property.name431 431 && value.property.name === 'isRequired' 432 432 ) { … … 448 448 // Verify PropTypes that are functions 449 449 if ( 450 value 451 && value.type === 'CallExpression' 450 astUtil.isCallExpression(value) 452 451 && value.callee 453 452 && value.callee.property … … 498 497 if ( 499 498 !argument.elements 500 || !argument.elements.length499 || argument.elements.length === 0 501 500 ) { 502 501 // Invalid proptype or cannot analyse statically … … 577 576 function filterInterfaceOrAliasByName(node, typeName) { 578 577 return ( 579 (node.id && node.id.name === typeName) 580 || (node.declaration && node.declaration.id && node.declaration.id.name === typeName) 578 node.id 579 && node.id.name === typeName 580 ) || ( 581 node.declaration 582 && node.declaration.id 583 && node.declaration.id.name === typeName 581 584 ); 582 585 } … … 638 641 const leftMostName = getLeftMostTypeName(node.typeName); 639 642 const shouldTraverseTypeParams = genericReactTypesImport.has(leftMostName); 640 const nodeType Params = node.typeParameters;641 if (shouldTraverseTypeParams && nodeType Params && nodeTypeParams.length !== 0) {643 const nodeTypeArguments = propsUtil.getTypeArguments(node); 644 if (shouldTraverseTypeParams && nodeTypeArguments && nodeTypeArguments.length !== 0) { 642 645 // All react Generic types are derived from: 643 646 // type PropsWithChildren<P> = P & { children?: ReactNode | undefined } … … 661 664 leftMostName !== rightMostName ? rightMostName : importedName 662 665 ]; 663 const nextNode = nodeType Params.params[idx];666 const nextNode = nodeTypeArguments.params[idx]; 664 667 this.visitTSNode(nextNode); 665 668 return; … … 696 699 const declarations = flatMap( 697 700 candidateTypes, 698 (type) => type.declarations || (type.declaration && type.declaration.declarations) || type.declaration); 701 (type) => ( 702 type.declarations 703 || ( 704 type.declaration 705 && type.declaration.declarations 706 ) 707 || type.declaration 708 ) 709 ); 699 710 700 711 // we tried to find either an interface or a type with the TypeReference name … … 750 761 convertReturnTypeToPropTypes(node, rootNode) { 751 762 // ReturnType<T> should always have one parameter 752 const nodeType Params = node.typeParameters;753 if (nodeType Params) {754 if (nodeType Params.params.length === 1) {755 let returnType = nodeType Params.params[0];763 const nodeTypeArguments = propsUtil.getTypeArguments(node); 764 if (nodeTypeArguments) { 765 if (nodeTypeArguments.params.length === 1) { 766 let returnType = nodeTypeArguments.params[0]; 756 767 // This line is trying to handle typescript-eslint-parser 757 768 // typescript-eslint-parser TSTypeQuery is wrapped by TSTypeReference … … 784 795 case 'ObjectExpression': 785 796 iterateProperties(context, res.properties, (key, value, propNode) => { 786 if (propNode && propNode.argument && propNode.argument.type === 'CallExpression') {787 const propNodeType Params = propNode.argument.typeParameters;788 if (propNodeType Params) {789 this.visitTSNode(propNodeType Params);797 if (propNode && astUtil.isCallExpression(propNode.argument)) { 798 const propNodeTypeArguments = propsUtil.getTypeArguments(propNode.argument); 799 if (propNodeTypeArguments) { 800 this.visitTSNode(propNodeTypeArguments); 790 801 } else { 791 802 // Ignore this CallExpression return value since it doesn't have any typeParameters to let us know it's types. … … 807 818 break; 808 819 case 'CallExpression': 809 if ( res.typeParameters) {810 this.visitTSNode( res.typeParameters);820 if (propsUtil.getTypeArguments(res)) { 821 this.visitTSNode(propsUtil.getTypeArguments(res)); 811 822 } else { 812 823 // Ignore this CallExpression return value since it doesn't have any typeParameters to let us know it's types. … … 993 1004 case 'GenericTypeAnnotation': 994 1005 if (propTypes.id.name === '$ReadOnly') { 995 const propType Params = propTypes.typeParameters;1006 const propTypeArguments = propsUtil.getTypeArguments(propTypes); 996 1007 ignorePropsValidation = declarePropTypesForObjectTypeAnnotation( 997 propType Params.params[0],1008 propTypeArguments.params[0], 998 1009 declaredPropTypes 999 1010 ); … … 1032 1043 } 1033 1044 1045 let propTypesArguments = null; 1046 if (node.parent) { 1047 propTypesArguments = propsUtil.getTypeArguments(node.parent); 1048 } 1049 1034 1050 if ( 1035 1051 node.parent 1036 1052 && node.parent.callee 1037 && node.parent.typeParameters1038 && node.parent.typeParameters.params1053 && propTypesArguments 1054 && propTypesArguments.params 1039 1055 && ( 1040 1056 node.parent.callee.name === 'forwardRef' || ( … … 1046 1062 ) 1047 1063 ) { 1048 const propTypesParams = node.parent.typeParameters;1049 1064 const declaredPropTypes = {}; 1050 const obj = new DeclarePropTypesForTSTypeAnnotation(propTypes Params.params[1], declaredPropTypes, rootNode);1065 const obj = new DeclarePropTypesForTSTypeAnnotation(propTypesArguments.params[1], declaredPropTypes, rootNode); 1051 1066 components.set(node, { 1052 1067 declaredPropTypes: obj.declaredPropTypes, … … 1094 1109 annotation 1095 1110 && annotation.type !== 'TSTypeReference' 1096 && annotation.typeParameters== null1111 && propsUtil.getTypeArguments(annotation) == null 1097 1112 ) { 1098 1113 return; … … 1106 1121 1107 1122 /** 1108 * Resolve the type annotation for a given class declaration node with superTypeParameters.1123 * Resolve the type annotation for a given class declaration node. 1109 1124 * 1110 1125 * @param {ASTNode} node The annotation or a node containing the type annotation. … … 1113 1128 function resolveSuperParameterPropsType(node) { 1114 1129 let propsParameterPosition; 1130 const parameters = propsUtil.getSuperTypeArguments(node); 1131 1115 1132 try { 1116 1133 // Flow <=0.52 had 3 required TypedParameters of which the second one is the Props. … … 1119 1136 } catch (e) { 1120 1137 // In case there is no flow version defined, we can safely assume that when there are 3 Props we are dealing with version <= 0.52 1121 propsParameterPosition = node.superTypeParameters.params.length <= 2 ? 0 : 1;1122 } 1123 1124 let annotation = node.superTypeParameters.params[propsParameterPosition];1138 propsParameterPosition = parameters.params.length <= 2 ? 0 : 1; 1139 } 1140 1141 let annotation = parameters.params[propsParameterPosition]; 1125 1142 while (annotation && (annotation.type === 'TypeAnnotation' || annotation.type === 'NullableTypeAnnotation')) { 1126 1143 annotation = annotation.typeAnnotation; … … 1136 1153 * Checks if we are declaring a `props` class property with a flow type annotation. 1137 1154 * @param {ASTNode} node The AST node being checked. 1138 * @returns { Boolean} True if the node is a type annotated props declaration, false if not.1155 * @returns {boolean} True if the node is a type annotated props declaration, false if not. 1139 1156 */ 1140 1157 function isAnnotatedClassPropsDeclaration(node) { -
imaps-frontend/node_modules/eslint-plugin-react/lib/util/propTypesSort.js
rd565449 r0c6b92a 17 17 * 18 18 * @param {ASTNode} node the node to check. 19 * @returns { String} The name of the node.19 * @returns {string} The name of the node. 20 20 */ 21 21 function getValueName(node) { 22 return node.type === 'Property' && node.value.property && node.value.property.name; 22 return node.type === 'Property' 23 && node.value.property 24 && node.value.property.name; 23 25 } 24 26 … … 27 29 * 28 30 * @param {ASTNode} node the prop to check. 29 * @returns { Boolean} true if the prop is required.31 * @returns {boolean} true if the prop is required. 30 32 */ 31 33 function isRequiredProp(node) { … … 36 38 * Checks if the proptype is a callback by checking if it starts with 'on'. 37 39 * 38 * @param { String} propName the name of the proptype to check.39 * @returns { Boolean} true if the proptype is a callback.40 * @param {string} propName the name of the proptype to check. 41 * @returns {boolean} true if the proptype is a callback. 40 42 */ 41 43 function isCallbackPropName(propName) { … … 47 49 * 48 50 * @param {ASTNode} node the prop to check. 49 * @returns { Boolean} true if the prop is PropTypes.shape.51 * @returns {boolean} true if the prop is PropTypes.shape. 50 52 */ 51 53 function isShapeProp(node) { 52 return Boolean( 53 node && node.callee && node.callee.property && node.callee.property.name === 'shape' 54 return !!( 55 node 56 && node.callee 57 && node.callee.property 58 && node.callee.property.name === 'shape' 54 59 ); 55 60 } … … 62 67 */ 63 68 function getShapeProperties(node) { 64 return node.arguments && node.arguments[0] && node.arguments[0].properties; 69 return node.arguments 70 && node.arguments[0] 71 && node.arguments[0].properties; 65 72 } 66 73 … … 71 78 * @param {ASTNode} b the second element to compare. 72 79 * @param {Context} context The context of the two nodes. 73 * @param { Boolean=} ignoreCase whether or not to ignore case when comparing the two elements.74 * @param { Boolean=} requiredFirst whether or not to sort required elements first.75 * @param { Boolean=} callbacksLast whether or not to sort callbacks after everything else.76 * @param { Boolean=} noSortAlphabetically whether or not to disable alphabetical sorting of the elements.77 * @returns { Number} the sort order of the two elements.80 * @param {boolean=} ignoreCase whether or not to ignore case when comparing the two elements. 81 * @param {boolean=} requiredFirst whether or not to sort required elements first. 82 * @param {boolean=} callbacksLast whether or not to sort callbacks after everything else. 83 * @param {boolean=} noSortAlphabetically whether or not to disable alphabetical sorting of the elements. 84 * @returns {number} the sort order of the two elements. 78 85 */ 79 86 function sorter(a, b, context, ignoreCase, requiredFirst, callbacksLast, noSortAlphabetically) { … … 122 129 * @param {Fixer} fixer the first element to compare. 123 130 * @param {Array} declarations The context of the two nodes. 124 * @param { Boolean=} ignoreCase whether or not to ignore case when comparing the two elements.125 * @param { Boolean=} requiredFirst whether or not to sort required elements first.126 * @param { Boolean=} callbacksLast whether or not to sort callbacks after everything else.127 * @param { Boolean=} noSortAlphabetically whether or not to disable alphabetical sorting of the elements.128 * @param { Boolean=} sortShapeProp whether or not to sort propTypes defined in PropTypes.shape.129 * @param { Boolean=} checkTypes whether or not sorting of prop type definitions are checked.131 * @param {boolean=} ignoreCase whether or not to ignore case when comparing the two elements. 132 * @param {boolean=} requiredFirst whether or not to sort required elements first. 133 * @param {boolean=} callbacksLast whether or not to sort callbacks after everything else. 134 * @param {boolean=} noSortAlphabetically whether or not to disable alphabetical sorting of the elements. 135 * @param {boolean=} sortShapeProp whether or not to sort propTypes defined in PropTypes.shape. 136 * @param {boolean=} checkTypes whether or not sorting of prop type definitions are checked. 130 137 * @returns {Object|*|{range, text}} the sort order of the two elements. 131 138 */ … … 221 228 module.exports = { 222 229 fixPropTypesSort, 230 isCallbackPropName, 231 isRequiredProp, 232 isShapeProp, 223 233 }; -
imaps-frontend/node_modules/eslint-plugin-react/lib/util/props.js
rd565449 r0c6b92a 10 10 * Checks if the Identifier node passed in looks like a propTypes declaration. 11 11 * @param {ASTNode} node The node to check. Must be an Identifier node. 12 * @returns { Boolean} `true` if the node is a propTypes declaration, `false` if not12 * @returns {boolean} `true` if the node is a propTypes declaration, `false` if not 13 13 */ 14 14 function isPropTypesDeclaration(node) { … … 25 25 * Checks if the node passed in looks like a contextTypes declaration. 26 26 * @param {ASTNode} node The node to check. 27 * @returns { Boolean} `true` if the node is a contextTypes declaration, `false` if not27 * @returns {boolean} `true` if the node is a contextTypes declaration, `false` if not 28 28 */ 29 29 function isContextTypesDeclaration(node) { … … 40 40 * Checks if the node passed in looks like a contextType declaration. 41 41 * @param {ASTNode} node The node to check. 42 * @returns { Boolean} `true` if the node is a contextType declaration, `false` if not42 * @returns {boolean} `true` if the node is a contextType declaration, `false` if not 43 43 */ 44 44 function isContextTypeDeclaration(node) { … … 49 49 * Checks if the node passed in looks like a childContextTypes declaration. 50 50 * @param {ASTNode} node The node to check. 51 * @returns { Boolean} `true` if the node is a childContextTypes declaration, `false` if not51 * @returns {boolean} `true` if the node is a childContextTypes declaration, `false` if not 52 52 */ 53 53 function isChildContextTypesDeclaration(node) { … … 58 58 * Checks if the Identifier node passed in looks like a defaultProps declaration. 59 59 * @param {ASTNode} node The node to check. Must be an Identifier node. 60 * @returns { Boolean} `true` if the node is a defaultProps declaration, `false` if not60 * @returns {boolean} `true` if the node is a defaultProps declaration, `false` if not 61 61 */ 62 62 function isDefaultPropsDeclaration(node) { … … 68 68 * Checks if we are declaring a display name 69 69 * @param {ASTNode} node The AST node being checked. 70 * @returns { Boolean} True if we are declaring a display name, false if not.70 * @returns {boolean} True if we are declaring a display name, false if not. 71 71 */ 72 72 function isDisplayNameDeclaration(node) { … … 87 87 * Checks if the PropTypes MemberExpression node passed in declares a required propType. 88 88 * @param {ASTNode} propTypeExpression node to check. Must be a `PropTypes` MemberExpression. 89 * @returns { Boolean} `true` if this PropType is required, `false` if not.89 * @returns {boolean} `true` if this PropType is required, `false` if not. 90 90 */ 91 91 function isRequiredPropType(propTypeExpression) { 92 return propTypeExpression.type === 'MemberExpression' && propTypeExpression.property.name === 'isRequired'; 92 return propTypeExpression.type === 'MemberExpression' 93 && propTypeExpression.property.name === 'isRequired'; 94 } 95 96 /** 97 * Returns the type arguments of a node or type parameters if type arguments are not available. 98 * @param {ASTNode} node The node to get the type arguments from. 99 * @returns {ASTNode} The type arguments or type parameters of the node. 100 */ 101 function getTypeArguments(node) { 102 if ('typeArguments' in node) { 103 return node.typeArguments; 104 } 105 return node.typeParameters; 106 } 107 108 /** 109 * Returns the super type arguments of a node or super type parameters if type arguments are not available. 110 * @param {ASTNode} node The node to get the super type arguments from. 111 * @returns {ASTNode} The super type arguments or parameters of the node. 112 */ 113 function getSuperTypeArguments(node) { 114 if ('superTypeArguments' in node) { 115 return node.superTypeArguments; 116 } 117 return node.superTypeParameters; 93 118 } 94 119 … … 101 126 isDisplayNameDeclaration, 102 127 isRequiredPropType, 128 getTypeArguments, 129 getSuperTypeArguments, 103 130 }; -
imaps-frontend/node_modules/eslint-plugin-react/lib/util/usedPropTypes.js
rd565449 r0c6b92a 67 67 * Checks if the string is one of `props`, `nextProps`, or `prevProps` 68 68 * @param {string} name The AST node being checked. 69 * @returns { Boolean} True if the prop name matches69 * @returns {boolean} True if the prop name matches 70 70 */ 71 71 function isCommonVariableNameForProps(name) { … … 76 76 * Checks if the component must be validated 77 77 * @param {Object} component The component to process 78 * @returns { Boolean} True if the component must be validated, false if not.78 * @returns {boolean} True if the component must be validated, false if not. 79 79 */ 80 80 function mustBeValidated(component) { … … 111 111 * @param {ASTNode} node The AST node being checked. 112 112 * @param {boolean} checkAsyncSafeLifeCycles 113 * @return { Boolean} True if the node is a lifecycle method113 * @return {boolean} True if the node is a lifecycle method 114 114 */ 115 115 function isNodeALifeCycleMethod(node, checkAsyncSafeLifeCycles) { 116 const nodeKeyName = (node.key || /** @type {ASTNode} */ ({})).name; 117 118 if (node.kind === 'constructor') { 119 return true; 120 } 121 if (LIFE_CYCLE_METHODS.indexOf(nodeKeyName) >= 0) { 122 return true; 123 } 124 if (checkAsyncSafeLifeCycles && ASYNC_SAFE_LIFE_CYCLE_METHODS.indexOf(nodeKeyName) >= 0) { 125 return true; 116 if (node.key) { 117 if (node.kind === 'constructor') { 118 return true; 119 } 120 121 const nodeKeyName = node.key.name; 122 123 if (typeof nodeKeyName !== 'string') { 124 return false; 125 } 126 127 if (LIFE_CYCLE_METHODS.indexOf(nodeKeyName) >= 0) { 128 return true; 129 } 130 if (checkAsyncSafeLifeCycles && ASYNC_SAFE_LIFE_CYCLE_METHODS.indexOf(nodeKeyName) >= 0) { 131 return true; 132 } 126 133 } 127 134 … … 134 141 * @param {ASTNode} node The AST node being checked. 135 142 * @param {boolean} checkAsyncSafeLifeCycles 136 * @return { Boolean} True if the node is inside a lifecycle method143 * @return {boolean} True if the node is inside a lifecycle method 137 144 */ 138 145 function isInLifeCycleMethod(node, checkAsyncSafeLifeCycles) { 139 if ((node.type === 'MethodDefinition' || node.type === 'Property') && isNodeALifeCycleMethod(node, checkAsyncSafeLifeCycles)) { 146 if ( 147 (node.type === 'MethodDefinition' || node.type === 'Property') 148 && isNodeALifeCycleMethod(node, checkAsyncSafeLifeCycles) 149 ) { 140 150 return true; 141 151 } … … 154 164 */ 155 165 function isSetStateUpdater(node) { 156 const unwrappedParentCalleeNode = node.parent && node.parent.type === 'CallExpression'166 const unwrappedParentCalleeNode = astUtil.isCallExpression(node.parent) 157 167 && ast.unwrapTSAsExpression(node.parent.callee); 158 168 … … 171 181 while (scope) { 172 182 const unwrappedParentCalleeNode = scope.block 173 && scope.block.parent 174 && scope.block.parent.type === 'CallExpression' 183 && astUtil.isCallExpression(scope.block.parent) 175 184 && ast.unwrapTSAsExpression(scope.block.parent.callee); 176 185 if ( … … 215 224 * @param {object} context 216 225 * @param {ASTNode} node The AST node being marked. 217 * @returns { Boolean} True if the prop has spread operator, false if not.226 * @returns {boolean} True if the prop has spread operator, false if not. 218 227 */ 219 228 function hasSpreadOperator(context, node) { -
imaps-frontend/node_modules/eslint-plugin-react/lib/util/variable.js
rd565449 r0c6b92a 12 12 * @param {Array} variables The variables list. 13 13 * @param {string} name The name of the variable to search. 14 * @returns { Boolean} True if the variable was found, false if not.14 * @returns {boolean} True if the variable was found, false if not. 15 15 */ 16 16 function findVariable(variables, name) {
Note:
See TracChangeset
for help on using the changeset viewer.