This rule forbids the assignment of values returned by the fill
, reverse
and sort
array methods. These methods modify the array in place and return the array itself. When assigned to a variable - or passed to a function as an argument - the code reads like it returns a modified copy of the array, but it does not.
Assignment is allowed in situations in which fill
, reverse
or sort
is called on an intermediate array.
Examples of incorrect code for this rule:
const sorted = names.sort();
print(names.sort());
Examples of correct code for this rule:
names.sort();
const sorted = names.map(({ first }) => first).sort();
names.sort();
print(names);
This rule has no options.