Ignore:
Timestamp:
12/12/24 17:06:06 (5 weeks ago)
Author:
stefan toskovski <stefantoska84@…>
Branches:
main
Parents:
d565449
Message:

Pred finalna verzija

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  
    7171   *
    7272   * @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)
    7474   * @returns {Object} Added component object
    7575   */
     
    184184   * Components for which we are not confident are not counted
    185185   *
    186    * @returns {Number} Components list length
     186   * @returns {number} Components list length
    187187   */
    188188  length() {
     
    304304
    305305    /**
    306      * @param {ASTNode} ASTNode
     306     * @param {ASTNode} node
    307307     * @param {boolean=} strict
    308308     * @returns {boolean}
    309309     */
    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);
    320320    },
    321321
     
    408408
    409409    isPragmaComponentWrapper(node) {
    410       if (!node || node.type !== 'CallExpression') {
     410      if (!astUtil.isCallExpression(node)) {
    411411        return false;
    412412      }
     
    568568
    569569        // 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        ) {
    571577          return undefined;
    572578        }
     
    578584          )
    579585        ) {
    580           if (isFirstLetterCapitalized(node.parent.key.name) && utils.isReturningJSX(node)) {
     586          if (
     587            isFirstLetterCapitalized(node.parent.key.name)
     588            && utils.isReturningJSX(node)
     589          ) {
    581590            return node;
    582591          }
     
    642651     *
    643652     * @param {ASTNode} node The AST node being checked (must be a MemberExpression).
    644      * @returns {ASTNode} component node, null if we cannot find the component
     653     * @returns {ASTNode | null} component node, null if we cannot find the component
    645654     */
    646655    getRelatedComponent(node) {
     
    752761     * @param {ASTNode} node The AST node being searched. (expects CallExpression)
    753762     * @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 hook
     763     * @returns {boolean} True if the node is a call to a React hook
    755764     */
    756765    isReactHookCall(node, expectedHookNames) {
    757       if (node.type !== 'CallExpression') {
     766      if (!astUtil.isCallExpression(node)) {
    758767        return false;
    759768      }
     
    799808
    800809      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      );
    803818      const isHookShadowed = isPotentialHookCall
    804819        && hookResolvedDefs
     
    877892      }
    878893
    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);
    884899    },
    885900
  • imaps-frontend/node_modules/eslint-plugin-react/lib/util/annotations.js

    rd565449 r0c6b92a  
    1313 * @param {ASTNode} node The AST node being checked.
    1414 * @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.
    1616 */
    1717function isAnnotatedFunctionPropsDeclaration(node, context) {
  • imaps-frontend/node_modules/eslint-plugin-react/lib/util/ast.js

    rd565449 r0c6b92a  
    9393
    9494  /* TODO: properly warn on React.forwardRefs having typo properties
    95   if (nodeType === 'CallExpression') {
     95  if (astUtil.isCallExpression(ASTNode)) {
    9696    const callee = ASTNode.callee;
    9797    const pragma = pragmaUtil.getFromContext(context);
     
    149149 */
    150150function 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  ) {
    152156    return node.key;
    153157  }
     
    161165 * Get properties name
    162166 * @param {Object} node - Property.
    163  * @returns {String} Property name.
     167 * @returns {string} Property name.
    164168 */
    165169function getPropertyName(node) {
     
    211215 * @param {Object} context The node to check
    212216 * @param {ASTNode} node The node to check
    213  * @return {Boolean} true if it's the first node in its line
     217 * @return {boolean} true if it's the first node in its line
    214218 */
    215219function isNodeFirstInLine(context, node) {
     
    223227 * Checks if the node is a function or arrow function expression.
    224228 * @param {ASTNode} node The node to check
    225  * @return {Boolean} true if it's a function-like expression
     229 * @return {boolean} true if it's a function-like expression
    226230 */
    227231function isFunctionLikeExpression(node) {
     
    232236 * Checks if the node is a function.
    233237 * @param {ASTNode} node The node to check
    234  * @return {Boolean} true if it's a function
     238 * @return {boolean} true if it's a function
    235239 */
    236240function isFunction(node) {
     
    241245 * Checks if node is a function declaration or expression or arrow function.
    242246 * @param {ASTNode} node The node to check
    243  * @return {Boolean} true if it's a function-like
     247 * @return {boolean} true if it's a function-like
    244248 */
    245249function isFunctionLike(node) {
     
    250254 * Checks if the node is a class.
    251255 * @param {ASTNode} node The node to check
    252  * @return {Boolean} true if it's a class
     256 * @return {boolean} true if it's a class
    253257 */
    254258function isClass(node) {
     
    330334 * Checks if a node is being assigned a value: props.bar = 'bar'
    331335 * @param {ASTNode} node The AST node being checked.
    332  * @returns {Boolean}
     336 * @returns {boolean}
    333337 */
    334338function isAssignmentLHS(node) {
     
    340344}
    341345
     346function 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 */
     355function isCallExpression(node) {
     356  return node && node.type === 'CallExpression';
     357}
     358
    342359/**
    343360 * Extracts the expression node that is wrapped inside a TS type assertion
     
    347364 */
    348365function unwrapTSAsExpression(node) {
    349   if (node && node.type === 'TSAsExpression') return node.expression;
    350   return node;
     366  return isTSAsExpression(node) ? node.expression : node;
    351367}
    352368
    353369function isTSTypeReference(node) {
    354370  if (!node) return false;
    355   const nodeType = node.type;
    356   return nodeType === 'TSTypeReference';
     371
     372  return node.type === 'TSTypeReference';
    357373}
    358374
    359375function isTSTypeAnnotation(node) {
    360   if (!node) return false;
    361   const nodeType = node.type;
    362   return nodeType === 'TSTypeAnnotation';
     376  if (!node) { return false; }
     377
     378  return node.type === 'TSTypeAnnotation';
    363379}
    364380
    365381function isTSTypeLiteral(node) {
    366   if (!node) return false;
    367   const nodeType = node.type;
    368   return nodeType === 'TSTypeLiteral';
     382  if (!node) { return false; }
     383
     384  return node.type === 'TSTypeLiteral';
    369385}
    370386
    371387function isTSIntersectionType(node) {
    372   if (!node) return false;
    373   const nodeType = node.type;
    374   return nodeType === 'TSIntersectionType';
     388  if (!node) { return false; }
     389
     390  return node.type === 'TSIntersectionType';
    375391}
    376392
    377393function isTSInterfaceHeritage(node) {
    378   if (!node) return false;
    379   const nodeType = node.type;
    380   return nodeType === 'TSInterfaceHeritage';
     394  if (!node) { return false; }
     395
     396  return node.type === 'TSInterfaceHeritage';
    381397}
    382398
    383399function 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
     408function 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
     418function isTSTypeAliasDeclaration(node) {
     419  if (!node) { return false; }
     420
    386421  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';
    411425}
    412426
    413427function isTSParenthesizedType(node) {
    414   if (!node) return false;
    415   const nodeType = node.type;
    416   return nodeType === 'TSTypeAliasDeclaration';
     428  if (!node) { return false; }
     429
     430  return node.type === 'TSTypeAliasDeclaration';
    417431}
    418432
    419433function isTSFunctionType(node) {
    420   if (!node) return false;
    421   const nodeType = node.type;
    422   return nodeType === 'TSFunctionType';
     434  if (!node) { return false; }
     435
     436  return node.type === 'TSFunctionType';
    423437}
    424438
    425439function isTSTypeQuery(node) {
    426   if (!node) return false;
    427   const nodeType = node.type;
    428   return nodeType === 'TSTypeQuery';
     440  if (!node) { return false; }
     441
     442  return node.type === 'TSTypeQuery';
    429443}
    430444
    431445function isTSTypeParameterInstantiation(node) {
    432   if (!node) return false;
    433   const nodeType = node.type;
    434   return nodeType === 'TSTypeParameterInstantiation';
     446  if (!node) { return false; }
     447
     448  return node.type === 'TSTypeParameterInstantiation';
    435449}
    436450
    437451module.exports = {
    438   traverse,
    439452  findReturnStatement,
     453  getComponentProperties,
    440454  getFirstNodeInLine,
     455  getKeyValue,
    441456  getPropertyName,
    442457  getPropertyNameNode,
    443   getComponentProperties,
    444   getKeyValue,
    445   isParenthesized,
     458  inConstructor,
    446459  isAssignmentLHS,
     460  isCallExpression,
    447461  isClass,
    448462  isFunction,
     463  isFunctionLike,
    449464  isFunctionLikeExpression,
    450   isFunctionLike,
    451   inConstructor,
    452465  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,
    453482  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,
    467483};
  • imaps-frontend/node_modules/eslint-plugin-react/lib/util/componentUtil.js

    rd565449 r0c6b92a  
    175175 */
    176176function 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';
    178180}
    179181
  • imaps-frontend/node_modules/eslint-plugin-react/lib/util/defaultProps.js

    rd565449 r0c6b92a  
    2727    }
    2828    if (
    29       node.type === 'CallExpression'
     29      astUtil.isCallExpression(node)
    3030      && propWrapperUtil.isPropWrapperFunction(context, node.callee.name)
    3131      && node.arguments && node.arguments[0]
  • imaps-frontend/node_modules/eslint-plugin-react/lib/util/error.js

    rd565449 r0c6b92a  
    33/**
    44 * 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.
    66 */
    77function error(message) {
  • imaps-frontend/node_modules/eslint-plugin-react/lib/util/isCreateContext.js

    rd565449 r0c6b92a  
    11'use strict';
     2
     3const astUtil = require('./ast');
    24
    35/**
    46 * Checks if the node is a React.createContext call
    57 * @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.
    79 */
    810module.exports = function isCreateContext(node) {
    911  if (
    1012    node.init
    11     && node.init.type === 'CallExpression'
    1213    && node.init.callee
    13     && node.init.callee.name === 'createContext'
    1414  ) {
    15     return true;
    16   }
     15    if (
     16      astUtil.isCallExpression(node.init)
     17      && node.init.callee.name === 'createContext'
     18    ) {
     19      return true;
     20    }
    1721
    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    }
    2629  }
    2730
     
    3033    && node.expression.type === 'AssignmentExpression'
    3134    && node.expression.operator === '='
    32     && node.expression.right.type === 'CallExpression'
     35    && astUtil.isCallExpression(node.expression.right)
    3336    && node.expression.right.callee
    34     && node.expression.right.callee.name === 'createContext'
    3537  ) {
    36     return true;
    37   }
     38    const right = node.expression.right;
    3839
    39   if (
    40     node.expression
    41     && node.expression.type === 'AssignmentExpression'
    42     && node.expression.operator === '='
    43     && node.expression.right.type === 'CallExpression'
    44     && node.expression.right.callee
    45     && node.expression.right.callee.type === 'MemberExpression'
    46     && node.expression.right.callee.property
    47     && 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    }
    5051  }
    5152
  • imaps-frontend/node_modules/eslint-plugin-react/lib/util/isCreateElement.js

    rd565449 r0c6b92a  
    1111*/
    1212module.exports = function isCreateElement(context, node) {
     13  if (!node.callee) {
     14    return false;
     15  }
     16
    1317  if (
    14     node.callee
    15     && node.callee.type === 'MemberExpression'
     18    node.callee.type === 'MemberExpression'
    1619    && node.callee.property.name === 'createElement'
    1720    && node.callee.object
     
    2225
    2326  if (
    24     node
    25     && node.callee
    26     && node.callee.name === 'createElement'
     27    node.callee.name === 'createElement'
    2728    && isDestructuredFromPragmaImport(context, node, 'createElement')
    2829  ) {
  • imaps-frontend/node_modules/eslint-plugin-react/lib/util/isDestructuredFromPragmaImport.js

    rd565449 r0c6b92a  
    11'use strict';
    22
     3const astUtil = require('./ast');
    34const pragmaUtil = require('./pragma');
    45const variableUtil = require('./variable');
     
    2324        if (
    2425          latestDef.node.init.type === 'MemberExpression'
    25               && latestDef.node.init.object.type === 'Identifier'
    26               && latestDef.node.init.object.name === pragma
     26          && latestDef.node.init.object.type === 'Identifier'
     27          && latestDef.node.init.object.name === pragma
    2728        ) {
    2829          return true;
     
    3132        if (
    3233          latestDef.node.init.type === 'Identifier'
    33               && latestDef.node.init.name === pragma
     34          && latestDef.node.init.name === pragma
    3435        ) {
    3536          return true;
     
    4041
    4142        // get "require('react')" from: "{variable} = require('react')"
    42         if (latestDef.node.init.type === 'CallExpression') {
     43        if (astUtil.isCallExpression(latestDef.node.init)) {
    4344          requireExpression = latestDef.node.init;
    4445        }
     
    4647        if (
    4748          !requireExpression
    48               && latestDef.node.init.type === 'MemberExpression'
    49               && latestDef.node.init.object.type === 'CallExpression'
     49          && latestDef.node.init.type === 'MemberExpression'
     50          && astUtil.isCallExpression(latestDef.node.init.object)
    5051        ) {
    5152          requireExpression = latestDef.node.init.object;
     
    5556        if (
    5657          requireExpression
    57               && requireExpression.callee
    58               && requireExpression.callee.name === 'require'
    59               && requireExpression.arguments[0]
    60               && requireExpression.arguments[0].value === pragma.toLocaleLowerCase()
     58          && requireExpression.callee
     59          && requireExpression.callee.name === 'require'
     60          && requireExpression.arguments[0]
     61          && requireExpression.arguments[0].value === pragma.toLocaleLowerCase()
    6162        ) {
    6263          return true;
     
    6970      if (
    7071        latestDef.parent
    71             && latestDef.parent.type === 'ImportDeclaration'
    72             && latestDef.parent.source.value === pragma.toLocaleLowerCase()
     72        && latestDef.parent.type === 'ImportDeclaration'
     73        && latestDef.parent.source.value === pragma.toLocaleLowerCase()
    7374      ) {
    7475        return true;
  • imaps-frontend/node_modules/eslint-plugin-react/lib/util/isFirstLetterCapitalized.js

    rd565449 r0c6b92a  
    33/**
    44 * Check if the first letter of a string is capitalized.
    5  * @param {String} word String to check
    6  * @returns {Boolean} True if first letter is capitalized.
     5 * @param {string} word String to check
     6 * @returns {boolean} True if first letter is capitalized.
    77 */
    8 function isFirstLetterCapitalized(word) {
     8module.exports = function isFirstLetterCapitalized(word) {
    99  if (!word) {
    1010    return false;
     
    1212  const firstLetter = word.replace(/^_+/, '').charAt(0);
    1313  return firstLetter.toUpperCase() === firstLetter;
    14 }
    15 
    16 module.exports = isFirstLetterCapitalized;
     14};
  • imaps-frontend/node_modules/eslint-plugin-react/lib/util/jsx.js

    rd565449 r0c6b92a  
    7777/**
    7878 * Check if value has only whitespaces
    79  * @param {string} value
     79 * @param {unknown} value
    8080 * @returns {boolean}
    8181 */
     
    8989 * @param {Context} context The context of `ASTNode`.
    9090 * @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 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
     91 * @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
    9494 */
    9595function isReturningJSX(context, ASTnode, strict, ignoreNull) {
     
    146146 * @param {ASTNode} ASTnode The AST node being checked
    147147 * @param {Context} context The context of `ASTNode`.
    148  * @returns {Boolean} True if the node is returning only null values
     148 * @returns {boolean} True if the node is returning only null values
    149149 */
    150150function isReturningOnlyNull(ASTnode, context) {
  • imaps-frontend/node_modules/eslint-plugin-react/lib/util/log.js

    rd565449 r0c6b92a  
    33/**
    44 * 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.
    66 */
    77function log(message) {
  • imaps-frontend/node_modules/eslint-plugin-react/lib/util/makeNoMethodSetStateRule.js

    rd565449 r0c6b92a  
    4545}
    4646
     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 */
    4753module.exports = function makeNoMethodSetStateRule(methodName, shouldCheckUnsafeCb) {
    4854  return {
     
    9197            callee.type !== 'MemberExpression'
    9298            || callee.object.type !== 'ThisExpression'
     99            || !('name' in callee.property)
    93100            || callee.property.name !== 'setState'
    94101          ) {
  • imaps-frontend/node_modules/eslint-plugin-react/lib/util/pragma.js

    rd565449 r0c6b92a  
    6363
    6464  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';
    6667  }
    6768  return pragma;
  • imaps-frontend/node_modules/eslint-plugin-react/lib/util/propTypes.js

    rd565449 r0c6b92a  
    2424 * Check if node is function type.
    2525 * @param {ASTNode} node
    26  * @returns {Boolean}
     26 * @returns {boolean}
    2727 */
    2828function isFunctionType(node) {
     
    3838 *
    3939 * @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.
    4141 */
    4242function isSuperTypeParameterPropsDeclaration(node) {
    4343  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) {
    4546      return true;
    4647    }
     
    7778 * Checks if a node is inside a class body.
    7879 *
    79  * @param {ASTNode} node  the AST node being checked.
    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.
    8182 */
    8283function isInsideClassBody(node) {
     
    153154  /**
    154155   * 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.
    157158   */
    158159  function hasCustomValidator(validator) {
     
    173174      let containsUnresolvedObjectTypeSpread = false;
    174175      let containsSpread = false;
    175       const containsIndexers = Boolean(annotation.indexers && annotation.indexers.length);
     176      const containsIndexers = !!annotation.indexers && annotation.indexers.length > 0;
    176177      const shapeTypeDefinition = {
    177178        type: 'shape',
     
    268269   * The representation is used to verify nested used properties.
    269270   * @param {ASTNode} annotation Type annotation for the props class property.
    270    * @param {String} parentName
     271   * @param {string} parentName
    271272   * @param {Set<ASTNode>} [seen]
    272273   * @return {Object} The representation of the declaration, empty object means
     
    297298   * @param {ASTNode} propTypes
    298299   * @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)
    300301   */
    301302  function declarePropTypesForObjectTypeAnnotation(propTypes, declaredPropTypes) {
     
    335336   * @param {ASTNode} propTypes
    336337   * @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)
    338339   */
    339340  function declarePropTypesForIntersectionTypeAnnotation(propTypes, declaredPropTypes) {
     
    428429      && value.type === 'MemberExpression'
    429430      && value.property
    430       && value.property.name
    431431      && value.property.name === 'isRequired'
    432432    ) {
     
    448448    // Verify PropTypes that are functions
    449449    if (
    450       value
    451       && value.type === 'CallExpression'
     450      astUtil.isCallExpression(value)
    452451      && value.callee
    453452      && value.callee.property
     
    498497          if (
    499498            !argument.elements
    500             || !argument.elements.length
     499            || argument.elements.length === 0
    501500          ) {
    502501            // Invalid proptype or cannot analyse statically
     
    577576  function filterInterfaceOrAliasByName(node, typeName) {
    578577    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
    581584    );
    582585  }
     
    638641        const leftMostName = getLeftMostTypeName(node.typeName);
    639642        const shouldTraverseTypeParams = genericReactTypesImport.has(leftMostName);
    640         const nodeTypeParams = node.typeParameters;
    641         if (shouldTraverseTypeParams && nodeTypeParams && nodeTypeParams.length !== 0) {
     643        const nodeTypeArguments = propsUtil.getTypeArguments(node);
     644        if (shouldTraverseTypeParams && nodeTypeArguments && nodeTypeArguments.length !== 0) {
    642645          // All react Generic types are derived from:
    643646          // type PropsWithChildren<P> = P & { children?: ReactNode | undefined }
     
    661664            leftMostName !== rightMostName ? rightMostName : importedName
    662665          ];
    663           const nextNode = nodeTypeParams.params[idx];
     666          const nextNode = nodeTypeArguments.params[idx];
    664667          this.visitTSNode(nextNode);
    665668          return;
     
    696699      const declarations = flatMap(
    697700        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      );
    699710
    700711      // we tried to find either an interface or a type with the TypeReference name
     
    750761    convertReturnTypeToPropTypes(node, rootNode) {
    751762      // ReturnType<T> should always have one parameter
    752       const nodeTypeParams = node.typeParameters;
    753       if (nodeTypeParams) {
    754         if (nodeTypeParams.params.length === 1) {
    755           let returnType = nodeTypeParams.params[0];
     763      const nodeTypeArguments = propsUtil.getTypeArguments(node);
     764      if (nodeTypeArguments) {
     765        if (nodeTypeArguments.params.length === 1) {
     766          let returnType = nodeTypeArguments.params[0];
    756767          // This line is trying to handle typescript-eslint-parser
    757768          // typescript-eslint-parser TSTypeQuery is wrapped by TSTypeReference
     
    784795                    case 'ObjectExpression':
    785796                      iterateProperties(context, res.properties, (key, value, propNode) => {
    786                         if (propNode && propNode.argument && propNode.argument.type === 'CallExpression') {
    787                           const propNodeTypeParams = propNode.argument.typeParameters;
    788                           if (propNodeTypeParams) {
    789                             this.visitTSNode(propNodeTypeParams);
     797                        if (propNode && astUtil.isCallExpression(propNode.argument)) {
     798                          const propNodeTypeArguments = propsUtil.getTypeArguments(propNode.argument);
     799                          if (propNodeTypeArguments) {
     800                            this.visitTSNode(propNodeTypeArguments);
    790801                          } else {
    791802                            // Ignore this CallExpression return value since it doesn't have any typeParameters to let us know it's types.
     
    807818                      break;
    808819                    case 'CallExpression':
    809                       if (res.typeParameters) {
    810                         this.visitTSNode(res.typeParameters);
     820                      if (propsUtil.getTypeArguments(res)) {
     821                        this.visitTSNode(propsUtil.getTypeArguments(res));
    811822                      } else {
    812823                        // Ignore this CallExpression return value since it doesn't have any typeParameters to let us know it's types.
     
    9931004      case 'GenericTypeAnnotation':
    9941005        if (propTypes.id.name === '$ReadOnly') {
    995           const propTypeParams = propTypes.typeParameters;
     1006          const propTypeArguments = propsUtil.getTypeArguments(propTypes);
    9961007          ignorePropsValidation = declarePropTypesForObjectTypeAnnotation(
    997             propTypeParams.params[0],
     1008            propTypeArguments.params[0],
    9981009            declaredPropTypes
    9991010          );
     
    10321043    }
    10331044
     1045    let propTypesArguments = null;
     1046    if (node.parent) {
     1047      propTypesArguments = propsUtil.getTypeArguments(node.parent);
     1048    }
     1049
    10341050    if (
    10351051      node.parent
    10361052      && node.parent.callee
    1037       && node.parent.typeParameters
    1038       && node.parent.typeParameters.params
     1053      && propTypesArguments
     1054      && propTypesArguments.params
    10391055      && (
    10401056        node.parent.callee.name === 'forwardRef' || (
     
    10461062      )
    10471063    ) {
    1048       const propTypesParams = node.parent.typeParameters;
    10491064      const declaredPropTypes = {};
    1050       const obj = new DeclarePropTypesForTSTypeAnnotation(propTypesParams.params[1], declaredPropTypes, rootNode);
     1065      const obj = new DeclarePropTypesForTSTypeAnnotation(propTypesArguments.params[1], declaredPropTypes, rootNode);
    10511066      components.set(node, {
    10521067        declaredPropTypes: obj.declaredPropTypes,
     
    10941109        annotation
    10951110        && annotation.type !== 'TSTypeReference'
    1096         && annotation.typeParameters == null
     1111        && propsUtil.getTypeArguments(annotation) == null
    10971112      ) {
    10981113        return;
     
    11061121
    11071122  /**
    1108    * Resolve the type annotation for a given class declaration node with superTypeParameters.
     1123   * Resolve the type annotation for a given class declaration node.
    11091124   *
    11101125   * @param {ASTNode} node The annotation or a node containing the type annotation.
     
    11131128  function resolveSuperParameterPropsType(node) {
    11141129    let propsParameterPosition;
     1130    const parameters = propsUtil.getSuperTypeArguments(node);
     1131
    11151132    try {
    11161133      // Flow <=0.52 had 3 required TypedParameters of which the second one is the Props.
     
    11191136    } catch (e) {
    11201137      // 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];
    11251142    while (annotation && (annotation.type === 'TypeAnnotation' || annotation.type === 'NullableTypeAnnotation')) {
    11261143      annotation = annotation.typeAnnotation;
     
    11361153   * Checks if we are declaring a `props` class property with a flow type annotation.
    11371154   * @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.
    11391156   */
    11401157  function isAnnotatedClassPropsDeclaration(node) {
  • imaps-frontend/node_modules/eslint-plugin-react/lib/util/propTypesSort.js

    rd565449 r0c6b92a  
    1717 *
    1818 * @param {ASTNode} node the node to check.
    19  * @returns {String} The name of the node.
     19 * @returns {string} The name of the node.
    2020 */
    2121function 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;
    2325}
    2426
     
    2729 *
    2830 * @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.
    3032 */
    3133function isRequiredProp(node) {
     
    3638 * Checks if the proptype is a callback by checking if it starts with 'on'.
    3739 *
    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.
    4042 */
    4143function isCallbackPropName(propName) {
     
    4749 *
    4850 * @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.
    5052 */
    5153function 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'
    5459  );
    5560}
     
    6267 */
    6368function 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;
    6572}
    6673
     
    7178 * @param {ASTNode} b the second element to compare.
    7279 * @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.
    7885 */
    7986function sorter(a, b, context, ignoreCase, requiredFirst, callbacksLast, noSortAlphabetically) {
     
    122129 * @param {Fixer} fixer the first element to compare.
    123130 * @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.
    130137 * @returns {Object|*|{range, text}} the sort order of the two elements.
    131138 */
     
    221228module.exports = {
    222229  fixPropTypesSort,
     230  isCallbackPropName,
     231  isRequiredProp,
     232  isShapeProp,
    223233};
  • imaps-frontend/node_modules/eslint-plugin-react/lib/util/props.js

    rd565449 r0c6b92a  
    1010 * Checks if the Identifier node passed in looks like a propTypes declaration.
    1111 * @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 not
     12 * @returns {boolean} `true` if the node is a propTypes declaration, `false` if not
    1313 */
    1414function isPropTypesDeclaration(node) {
     
    2525 * Checks if the node passed in looks like a contextTypes declaration.
    2626 * @param {ASTNode} node The node to check.
    27  * @returns {Boolean} `true` if the node is a contextTypes declaration, `false` if not
     27 * @returns {boolean} `true` if the node is a contextTypes declaration, `false` if not
    2828 */
    2929function isContextTypesDeclaration(node) {
     
    4040 * Checks if the node passed in looks like a contextType declaration.
    4141 * @param {ASTNode} node The node to check.
    42  * @returns {Boolean} `true` if the node is a contextType declaration, `false` if not
     42 * @returns {boolean} `true` if the node is a contextType declaration, `false` if not
    4343 */
    4444function isContextTypeDeclaration(node) {
     
    4949 * Checks if the node passed in looks like a childContextTypes declaration.
    5050 * @param {ASTNode} node The node to check.
    51  * @returns {Boolean} `true` if the node is a childContextTypes declaration, `false` if not
     51 * @returns {boolean} `true` if the node is a childContextTypes declaration, `false` if not
    5252 */
    5353function isChildContextTypesDeclaration(node) {
     
    5858 * Checks if the Identifier node passed in looks like a defaultProps declaration.
    5959 * @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 not
     60 * @returns {boolean} `true` if the node is a defaultProps declaration, `false` if not
    6161 */
    6262function isDefaultPropsDeclaration(node) {
     
    6868 * Checks if we are declaring a display name
    6969 * @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.
    7171 */
    7272function isDisplayNameDeclaration(node) {
     
    8787 * Checks if the PropTypes MemberExpression node passed in declares a required propType.
    8888 * @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.
    9090 */
    9191function 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 */
     101function 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 */
     113function getSuperTypeArguments(node) {
     114  if ('superTypeArguments' in node) {
     115    return node.superTypeArguments;
     116  }
     117  return node.superTypeParameters;
    93118}
    94119
     
    101126  isDisplayNameDeclaration,
    102127  isRequiredPropType,
     128  getTypeArguments,
     129  getSuperTypeArguments,
    103130};
  • imaps-frontend/node_modules/eslint-plugin-react/lib/util/usedPropTypes.js

    rd565449 r0c6b92a  
    6767 * Checks if the string is one of `props`, `nextProps`, or `prevProps`
    6868 * @param {string} name The AST node being checked.
    69  * @returns {Boolean} True if the prop name matches
     69 * @returns {boolean} True if the prop name matches
    7070 */
    7171function isCommonVariableNameForProps(name) {
     
    7676 * Checks if the component must be validated
    7777 * @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.
    7979 */
    8080function mustBeValidated(component) {
     
    111111 * @param {ASTNode} node The AST node being checked.
    112112 * @param {boolean} checkAsyncSafeLifeCycles
    113  * @return {Boolean} True if the node is a lifecycle method
     113 * @return {boolean} True if the node is a lifecycle method
    114114 */
    115115function 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    }
    126133  }
    127134
     
    134141 * @param {ASTNode} node The AST node being checked.
    135142 * @param {boolean} checkAsyncSafeLifeCycles
    136  * @return {Boolean} True if the node is inside a lifecycle method
     143 * @return {boolean} True if the node is inside a lifecycle method
    137144 */
    138145function 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  ) {
    140150    return true;
    141151  }
     
    154164 */
    155165function isSetStateUpdater(node) {
    156   const unwrappedParentCalleeNode = node.parent && node.parent.type === 'CallExpression'
     166  const unwrappedParentCalleeNode = astUtil.isCallExpression(node.parent)
    157167    && ast.unwrapTSAsExpression(node.parent.callee);
    158168
     
    171181  while (scope) {
    172182    const unwrappedParentCalleeNode = scope.block
    173       && scope.block.parent
    174       && scope.block.parent.type === 'CallExpression'
     183      && astUtil.isCallExpression(scope.block.parent)
    175184      && ast.unwrapTSAsExpression(scope.block.parent.callee);
    176185    if (
     
    215224 * @param {object} context
    216225 * @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.
    218227 */
    219228function hasSpreadOperator(context, node) {
  • imaps-frontend/node_modules/eslint-plugin-react/lib/util/variable.js

    rd565449 r0c6b92a  
    1212 * @param {Array} variables The variables list.
    1313 * @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.
    1515 */
    1616function findVariable(variables, name) {
Note: See TracChangeset for help on using the changeset viewer.