Changeset 0c6b92a for imaps-frontend/node_modules/eslint-plugin-react/lib/rules/no-unstable-nested-components.js
Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/eslint-plugin-react/lib/rules/no-unstable-nested-components.js
rd565449 r0c6b92a 6 6 'use strict'; 7 7 8 const minimatch = require('minimatch'); 8 9 const Components = require('../util/Components'); 9 10 const docsUrl = require('../util/docsUrl'); 11 const astUtil = require('../util/ast'); 10 12 const isCreateElement = require('../util/isCreateElement'); 11 13 const report = require('../util/report'); … … 24 26 /** 25 27 * Generate error message with given parent component name 26 * @param { String} parentName Name of the parent component, if known27 * @returns { String} Error message with parent component name28 * @param {string} parentName Name of the parent component, if known 29 * @returns {string} Error message with parent component name 28 30 */ 29 31 function generateErrorMessageWithParentName(parentName) { … … 32 34 33 35 /** 34 * Check whether given text starts with `render`. Comparison is case-sensitive. 35 * @param {String} text Text to validate 36 * @returns {Boolean} 37 */ 38 function startsWithRender(text) { 39 return (text || '').startsWith('render'); 36 * Check whether given text matches the pattern passed in. 37 * @param {string} text Text to validate 38 * @param {string} pattern Pattern to match against 39 * @returns {boolean} 40 */ 41 function propMatchesRenderPropPattern(text, pattern) { 42 return typeof text === 'string' && minimatch(text, pattern); 40 43 } 41 44 … … 63 66 * @param {ASTNode} node The AST node 64 67 * @param {Context} context eslint context 65 * @returns { Boolean} True if node is a `createElement` call, false if not68 * @returns {boolean} True if node is a `createElement` call, false if not 66 69 */ 67 70 function isCreateElementMatcher(node, context) { 68 71 return ( 69 node 70 && node.type === 'CallExpression' 72 astUtil.isCallExpression(node) 71 73 && isCreateElement(context, node) 72 74 ); … … 76 78 * Matcher used to check whether given node is a `ObjectExpression` 77 79 * @param {ASTNode} node The AST node 78 * @returns { Boolean} True if node is a `ObjectExpression`, false if not80 * @returns {boolean} True if node is a `ObjectExpression`, false if not 79 81 */ 80 82 function isObjectExpressionMatcher(node) { … … 85 87 * Matcher used to check whether given node is a `JSXExpressionContainer` 86 88 * @param {ASTNode} node The AST node 87 * @returns { Boolean} True if node is a `JSXExpressionContainer`, false if not89 * @returns {boolean} True if node is a `JSXExpressionContainer`, false if not 88 90 */ 89 91 function isJSXExpressionContainerMatcher(node) { … … 94 96 * Matcher used to check whether given node is a `JSXAttribute` of `JSXExpressionContainer` 95 97 * @param {ASTNode} node The AST node 96 * @returns { Boolean} True if node is a `JSXAttribute` of `JSXExpressionContainer`, false if not98 * @returns {boolean} True if node is a `JSXAttribute` of `JSXExpressionContainer`, false if not 97 99 */ 98 100 function isJSXAttributeOfExpressionContainerMatcher(node) { … … 108 110 * Matcher used to check whether given node is an object `Property` 109 111 * @param {ASTNode} node The AST node 110 * @returns { Boolean} True if node is a `Property`, false if not112 * @returns {boolean} True if node is a `Property`, false if not 111 113 */ 112 114 function isPropertyOfObjectExpressionMatcher(node) { … … 116 118 && node.parent.type === 'Property' 117 119 ); 118 }119 120 /**121 * Matcher used to check whether given node is a `CallExpression`122 * @param {ASTNode} node The AST node123 * @returns {Boolean} True if node is a `CallExpression`, false if not124 */125 function isCallExpressionMatcher(node) {126 return node && node.type === 'CallExpression';127 120 } 128 121 … … 133 126 * ``` 134 127 * @param {ASTNode} node The AST node 135 * @returns { Boolean} True if node is directly inside `map` call, false if not128 * @returns {boolean} True if node is directly inside `map` call, false if not 136 129 */ 137 130 function isMapCall(node) { … … 148 141 * @param {ASTNode} node The AST node 149 142 * @param {Context} context eslint context 150 * @returns { Boolean} True if node is a `ReturnStatement` of a React hook, false if not143 * @returns {boolean} True if node is a `ReturnStatement` of a React hook, false if not 151 144 */ 152 145 function isReturnStatementOfHook(node, context) { … … 159 152 } 160 153 161 const callExpression = getClosestMatchingParent(node, context, isCallExpressionMatcher);154 const callExpression = getClosestMatchingParent(node, context, astUtil.isCallExpression); 162 155 return ( 163 156 callExpression … … 175 168 * @param {ASTNode} node The AST node 176 169 * @param {Context} context eslint context 177 * @returns {Boolean} True if component is declared inside a render prop, false if not 178 */ 179 function isComponentInRenderProp(node, context) { 170 * @param {string} propNamePattern a pattern to match render props against 171 * @returns {boolean} True if component is declared inside a render prop, false if not 172 */ 173 function isComponentInRenderProp(node, context, propNamePattern) { 180 174 if ( 181 175 node … … 183 177 && node.parent.type === 'Property' 184 178 && node.parent.key 185 && startsWithRender(node.parent.key.name)179 && propMatchesRenderPropPattern(node.parent.key.name, propNamePattern) 186 180 ) { 187 181 return true; … … 212 206 213 207 // Starts with render, e.g. <Component renderFooter={() => <div />} /> 214 if ( startsWithRender(propName)) {208 if (propMatchesRenderPropPattern(propName, propNamePattern)) { 215 209 return true; 216 210 } … … 232 226 * ``` 233 227 * @param {ASTNode} node The AST node 234 * @returns {Boolean} True if component is declared inside a render property, false if not 235 */ 236 function isDirectValueOfRenderProperty(node) { 228 * @param {string} propNamePattern The pattern to match render props against 229 * @returns {boolean} True if component is declared inside a render property, false if not 230 */ 231 function isDirectValueOfRenderProperty(node, propNamePattern) { 237 232 return ( 238 233 node … … 241 236 && node.parent.key 242 237 && node.parent.key.type === 'Identifier' 243 && startsWithRender(node.parent.key.name)238 && propMatchesRenderPropPattern(node.parent.key.name, propNamePattern) 244 239 ); 245 240 } … … 248 243 * Resolve the component name of given node 249 244 * @param {ASTNode} node The AST node of the component 250 * @returns { String} Name of the component, if any245 * @returns {string} Name of the component, if any 251 246 */ 252 247 function resolveComponentName(node) { … … 287 282 type: 'boolean', 288 283 }, 284 propNamePattern: { 285 type: 'string', 286 }, 289 287 }, 290 288 additionalProperties: false, … … 294 292 create: Components.detect((context, components, utils) => { 295 293 const allowAsProps = context.options.some((option) => option && option.allowAsProps); 294 const propNamePattern = (context.options[0] || {}).propNamePattern || 'render*'; 296 295 297 296 /** … … 304 303 * ``` 305 304 * @param {ASTNode} node The AST node being checked 306 * @returns { Boolean} True if node is inside class component's render block, false if not305 * @returns {boolean} True if node is inside class component's render block, false if not 307 306 */ 308 307 function isInsideRenderMethod(node) { … … 332 331 * ``` 333 332 * @param {ASTNode} node The AST node being checked 334 * @returns { Boolean} True if given node a function component declared inside class component, false if not333 * @returns {boolean} True if given node a function component declared inside class component, false if not 335 334 */ 336 335 function isFunctionComponentInsideClassComponent(node) { … … 355 354 * ``` 356 355 * @param {ASTNode} node The AST node 357 * @returns { Boolean} True if node is declare inside `createElement` call's props, false if not356 * @returns {boolean} True if node is declare inside `createElement` call's props, false if not 358 357 */ 359 358 function isComponentInsideCreateElementsProp(node) { … … 378 377 * ``` 379 378 * @param {ASTNode} node The AST node being checked 380 * @returns { Boolean} True if node is a component declared inside prop, false if not379 * @returns {boolean} True if node is a component declared inside prop, false if not 381 380 */ 382 381 function isComponentInProp(node) { … … 400 399 * ``` 401 400 * @param {ASTNode} node The AST node being checked 402 * @returns { Boolean} True if node is a stateless component returning non-JSX, false if not401 * @returns {boolean} True if node is a stateless component returning non-JSX, false if not 403 402 */ 404 403 function isStatelessComponentReturningNull(node) { … … 428 427 if ( 429 428 // Support allowAsProps option 430 (isDeclaredInsideProps && (allowAsProps || isComponentInRenderProp(node, context )))429 (isDeclaredInsideProps && (allowAsProps || isComponentInRenderProp(node, context, propNamePattern))) 431 430 432 431 // Prevent reporting components created inside Array.map calls … … 438 437 439 438 // Do not mark objects containing render methods 440 || isDirectValueOfRenderProperty(node )439 || isDirectValueOfRenderProperty(node, propNamePattern) 441 440 442 441 // Prevent reporting nested class components twice
Note:
See TracChangeset
for help on using the changeset viewer.