Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
BridgeAR opened this issue May 29, 2025 · 0 comments
Open

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

BridgeAR opened this issue May 29, 2025 · 0 comments

Comments

@BridgeAR
Copy link

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

@github-actions github-actions bot changed the title rule-name: unicorn/no-for-loop rule-name: unicorn/no-for-loop May 29, 2025
@fisker fisker changed the title rule-name: unicorn/no-for-loop unicorn/no-for-loop: option to ignore cases uses index Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant