Changeset 0c6b92a for imaps-frontend/node_modules/eslint-plugin-react/lib/rules/no-access-state-in-setstate.js
Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/eslint-plugin-react/lib/rules/no-access-state-in-setstate.js
rd565449 r0c6b92a 7 7 8 8 const docsUrl = require('../util/docsUrl'); 9 const astUtil = require('../util/ast'); 9 10 const componentUtil = require('../util/componentUtil'); 10 11 const report = require('../util/report'); … … 19 20 }; 20 21 22 /** @type {import('eslint').Rule.RuleModule} */ 21 23 module.exports = { 22 24 meta: { … … 33 35 create(context) { 34 36 function isSetStateCall(node) { 35 return node.type === 'CallExpression'37 return astUtil.isCallExpression(node) 36 38 && node.callee.property 37 39 && node.callee.property.name === 'setState' … … 73 75 // method containing this.state to the methods array 74 76 methods.forEach((method) => { 75 if ( node.callee.name === method.methodName) {77 if ('name' in node.callee && node.callee.name === method.methodName) { 76 78 let current = node.parent; 77 79 while (current.type !== 'Program') { 78 80 if (current.type === 'MethodDefinition') { 79 81 methods.push({ 80 methodName: current.key.name,82 methodName: 'name' in current.key ? current.key.name : undefined, 81 83 node: method.node, 82 84 }); … … 93 95 while (current.type !== 'Program') { 94 96 if (isFirstArgumentInSetStateCall(current, node)) { 95 const methodName = node.callee.name;97 const methodName = 'name' in node.callee ? node.callee.name : undefined; 96 98 methods.forEach((method) => { 97 99 if (method.methodName === methodName) { … … 110 112 MemberExpression(node) { 111 113 if ( 112 node.property.name === 'state' 114 'name' in node.property 115 && node.property.name === 'state' 113 116 && node.object.type === 'ThisExpression' 114 117 && isClassComponent(node) 115 118 ) { 119 /** @type {import("eslint").Rule.Node} */ 116 120 let current = node; 117 121 while (current.type !== 'Program') { … … 127 131 if (current.type === 'MethodDefinition') { 128 132 methods.push({ 129 methodName: current.key.name, 130 node, 131 }); 132 break; 133 } else if (current.type === 'FunctionExpression' && current.parent.key) { 133 methodName: 'name' in current.key ? current.key.name : undefined, 134 node, 135 }); 136 break; 137 } else if ( 138 current.type === 'FunctionExpression' 139 && 'key' in current.parent 140 && current.parent.key 141 ) { 134 142 methods.push({ 135 methodName: current.parent.key.name,143 methodName: 'name' in current.parent.key ? current.parent.key.name : undefined, 136 144 node, 137 145 }); … … 144 152 node, 145 153 scope: getScope(context, node), 146 variableName: current.id.name,154 variableName: 'name' in current.id ? current.id.name : undefined, 147 155 }); 148 156 break; … … 156 164 Identifier(node) { 157 165 // Checks if the identifier is a variable within an object 166 /** @type {import("eslint").Rule.Node} */ 158 167 let current = node; 159 168 while (current.parent.type === 'BinaryExpression') { … … 161 170 } 162 171 if ( 163 current.parent.value === current164 || current.parent.object === current172 ('value' in current.parent && current.parent.value === current) 173 || ('object' in current.parent && current.parent.object === current) 165 174 ) { 166 175 while (current.type !== 'Program') { … … 180 189 181 190 ObjectPattern(node) { 182 const isDerivedFromThis = node.parent.init && node.parent.init.type === 'ThisExpression';191 const isDerivedFromThis = 'init' in node.parent && node.parent.init && node.parent.init.type === 'ThisExpression'; 183 192 node.properties.forEach((property) => { 184 if (property && property.key && property.key.name === 'state' && isDerivedFromThis) { 193 if ( 194 property 195 && 'key' in property 196 && property.key 197 && 'name' in property.key 198 && property.key.name === 'state' 199 && isDerivedFromThis 200 ) { 185 201 vars.push({ 186 202 node: property.key,
Note:
See TracChangeset
for help on using the changeset viewer.