@@ -16,6 +16,7 @@ const extendFixRange = require('./utils/extend-fix-range');
1616const isFunctionSelfUsedInside = require ( './utils/is-function-self-used-inside' ) ;
1717const { isNodeMatches} = require ( './utils/is-node-matches' ) ;
1818const assertToken = require ( './utils/assert-token' ) ;
19+ const referenceIdentifierSelector = require ( './utils/reference-identifier-selector' ) ;
1920
2021const MESSAGE_ID = 'no-array-for-each' ;
2122const messages = {
@@ -231,7 +232,7 @@ function isParameterSafeToFix(parameter, {scope, array, allIdentifiers}) {
231232
232233 const [ arrayStart , arrayEnd ] = array . range ;
233234 for ( const identifier of allIdentifiers ) {
234- const { name, range : [ start , end ] , parent } = identifier ;
235+ const { name, range : [ start , end ] } = identifier ;
235236 if (
236237 name !== parameterName ||
237238 start < arrayStart ||
@@ -240,31 +241,6 @@ function isParameterSafeToFix(parameter, {scope, array, allIdentifiers}) {
240241 continue ;
241242 }
242243
243- if (
244- (
245- (
246- parent . type === 'FunctionExpression' ||
247- parent . type === 'ClassExpression' ||
248- parent . type === 'FunctionDeclaration' ||
249- parent . type === 'ClassDeclaration'
250- ) &&
251- parent . id === identifier
252- ) ||
253- (
254- parent . type === 'MemberExpression' &&
255- ! parent . computed &&
256- parent . property === identifier
257- ) ||
258- (
259- parent . type === 'Property' &&
260- ! parent . shorthand &&
261- ! parent . computed &&
262- parent . key === identifier
263- )
264- ) {
265- continue ;
266- }
267-
268244 const variable = findVariable ( scope , identifier ) ;
269245 if ( ! variable || variable . scope === scope || isChildScope ( scope , variable . scope ) ) {
270246 return false ;
@@ -366,7 +342,7 @@ const create = context => {
366342 ':function:exit' ( ) {
367343 functionStack . pop ( ) ;
368344 } ,
369- Identifier ( node ) {
345+ [ referenceIdentifierSelector ( ) ] ( node ) {
370346 allIdentifiers . push ( node ) ;
371347 } ,
372348 ReturnStatement ( node ) {
0 commit comments