eslint-plugin-unicorn icon indicating copy to clipboard operation
eslint-plugin-unicorn copied to clipboard

`unicorn/no-for-loop`: option to ignore cases uses `index`

Open BridgeAR opened this issue 6 months ago • 1 comments

Description

The rule itself is great and works correct, it is just a bit strict for some code bases.

I would like to activate the rule, while only partially for now where all regular iterations would change. Adding an option to deactivate the rule for cases that would end up as: for (const [index, element] of array.entries()) would be great!

Something like: { noArrayEntriesTransformations: true }

I guess this pattern also has a performance overhead, while I must admit that I didn't check that and it's probably acceptable compared to the application code.

Examples

// ❌
for (let index = 0; index < array.length; index++) {
	const element = array[index];
    console.log(element)
}

// ✅
for (let index = 0; index < array.length; index++) {
	const element = array[index];
	console.log(index, element);
}

Additional Info

No response

BridgeAR avatar May 29 '25 17:05 BridgeAR