thoughtbot / eslint-config

A sharable ESLint configuration that enforces thoughtbot’s JavaScript guides.
https://thoughtbot.com
MIT License
10 stars 1 forks source link

Allow for...of loops #7

Open stevehanson opened 10 months ago

stevehanson commented 10 months ago

This rule originally comes from the Airbnb ruleset. These were restricted by Airbnb because browser support was lacking in 2018. Browser support for for...of is now at 97%. Additionally, not all of our users are writing for the browser. Finally, for...of loops are the simplest way to loop through arrays asynchronously in sequence:

// this works, but .forEach and for...in do not
for await (const item of items) {
  await doSomething(item);
}

Similarly, this PR allows the use of continue statements. We often encourage early returns in methods, and to me continue is a similar concept, but in the context of a loop. I don't see a need to be opinionated about its usage.

https://caniuse.com/?search=for...of