π Disallow confusing uses of Array#with().
πΌπ« This rule is enabled in the β
recommended config. This rule is disabled in the βοΈ unopinionated config.
Array#with() throws a RangeError when the index is outside the array bounds.
Avoid using a negative index when the array may be empty, and avoid passing .length as the index since it is always outside the valid range.
This rule intentionally does not try to detect length guards. Use Array#with() with a clearly valid index.
// β
const result = array.with(-1, value);
// β
const result = array.length === 0 ? array : array.with(array.length - 1, value);// β
const result = array.with(array.length, value);
// β
const result = [...array, value];