Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/eslint-plugin-react/lib/rules/no-string-refs.js
rd565449 r0c6b92a 9 9 const docsUrl = require('../util/docsUrl'); 10 10 const report = require('../util/report'); 11 const testReactVersion = require('../util/version').testReactVersion; 11 12 12 13 // ------------------------------------------------------------------------------ … … 43 44 44 45 create(context) { 46 const checkRefsUsage = testReactVersion(context, '< 18.3.0'); // `this.refs` is writable in React 18.3.0 and later, see https://github.com/facebook/react/pull/28867 45 47 const detectTemplateLiterals = context.options[0] ? context.options[0].noTemplateLiterals : false; 46 48 /** 47 49 * Checks if we are using refs 48 50 * @param {ASTNode} node The AST node being checked. 49 * @returns { Boolean} True if we are using refs, false if not.51 * @returns {boolean} True if we are using refs, false if not. 50 52 */ 51 53 function isRefsUsage(node) { … … 60 62 * Checks if we are using a ref attribute 61 63 * @param {ASTNode} node The AST node being checked. 62 * @returns { Boolean} True if we are using a ref attribute, false if not.64 * @returns {boolean} True if we are using a ref attribute, false if not. 63 65 */ 64 66 function isRefAttribute(node) { 65 return !!( 66 node.type === 'JSXAttribute' 67 && node.name 68 && node.name.name === 'ref' 69 ); 67 return node.type === 'JSXAttribute' 68 && !!node.name 69 && node.name.name === 'ref'; 70 70 } 71 71 … … 73 73 * Checks if a node contains a string value 74 74 * @param {ASTNode} node The AST node being checked. 75 * @returns { Boolean} True if the node contains a string value, false if not.75 * @returns {boolean} True if the node contains a string value, false if not. 76 76 */ 77 77 function containsStringLiteral(node) { 78 return !!( 79 node.value 78 return !!node.value 80 79 && node.value.type === 'Literal' 81 && typeof node.value.value === 'string' 82 ); 80 && typeof node.value.value === 'string'; 83 81 } 84 82 … … 86 84 * Checks if a node contains a string value within a jsx expression 87 85 * @param {ASTNode} node The AST node being checked. 88 * @returns { Boolean} True if the node contains a string value within a jsx expression, false if not.86 * @returns {boolean} True if the node contains a string value within a jsx expression, false if not. 89 87 */ 90 88 function containsStringExpressionContainer(node) { 91 return !!( 92 node.value 89 return !!node.value 93 90 && node.value.type === 'JSXExpressionContainer' 94 91 && node.value.expression 95 92 && ((node.value.expression.type === 'Literal' && typeof node.value.expression.value === 'string') 96 || (node.value.expression.type === 'TemplateLiteral' && detectTemplateLiterals)) 97 ); 93 || (node.value.expression.type === 'TemplateLiteral' && detectTemplateLiterals)); 98 94 } 99 95 100 96 return { 101 97 MemberExpression(node) { 102 if ( isRefsUsage(node)) {98 if (checkRefsUsage && isRefsUsage(node)) { 103 99 report(context, messages.thisRefsDeprecated, 'thisRefsDeprecated', { 104 100 node, … … 106 102 } 107 103 }, 104 108 105 JSXAttribute(node) { 109 106 if (
Note:
See TracChangeset
for help on using the changeset viewer.