Based on the issue discussion, it seems to me that our main goal with this rule is to push developers to use functional programming methods like .map(), .filter() etc instead of iteration with side effects.
Considering that, .forEach() seems just as bad as any for loop in this example.
I've updated the examples to demonstrate the use of more array methods and labelled their iteration variants as bad even if they use .forEach.
When side effects are unavoidable, .forEach doesn't really make anything more immutable or pure compared to for-of.
But I did include an example where it's preferable to use it.
Based on #6
I also noticed that previously, examples like this were labelled as "good" simply for using
.forEach
instead offor-of
:Based on the issue discussion, it seems to me that our main goal with this rule is to push developers to use functional programming methods like
.map()
,.filter()
etc instead of iteration with side effects.Considering that,
.forEach()
seems just as bad as any for loop in this example. I've updated the examples to demonstrate the use of more array methods and labelled their iteration variants as bad even if they use.forEach
.When side effects are unavoidable,
.forEach
doesn't really make anything more immutable or pure compared tofor-of
. But I did include an example where it's preferable to use it.