Open noftaly opened 3 years ago
Don't you think manually fix no-shadow
is easier than complicated forEach
case?
In you case above I would move .filter
out and assign to a new variable. Easy fix.
The rule is doing the correct thing here.
One thing I though of, is to add an option to disable this rule when using method chaining, because I think it looks better when using a forEach with method chaining, than using method chaining in a for of.
👎 The solution is to just:
In you case above I would move .filter out and assign to a new variable. Easy fix.
I had this code before, with an
Array#forEach
:The new
no-array-for-each
auto-fixed it to:But it used the name
topic
for the for loop, which is already used in the.map
and.filter
methods. This triggered theno-shadow
rule. I don't know if unicorn can do anything about it though, appart from extracting the array to a variable before the loop, or using a suggestion rather than a fix.One thing I though of, is to add an option to disable this rule when using method chaining, because I think it looks better when using a
forEach
with method chaining, than using method chaining in afor of
.