An array literal has a hole between two elements

tx0/ts:sparse-arrayrecommendedwarningbug

What it finds

[red, , blue]: a doubled comma between two elements leaves a hole in an array, which reads as undefined but is skipped by forEach, map and the other methods, and is usually a slip.

Only single holes between elements are reported. Holes at the start, as in [, null, undefined], and runs of holes are written on purpose, often to test how code treats them, and a trailing comma is not a hole. Arrays that are the target of a destructuring assignment, as in [first, , third] = list, use holes to skip elements and are left alone.

From the rule's source, sparse_array.rs.

Example from the rule's tests
const colors = ["red", , "blue"];tx0 reports: this array has a hole between two elementsconst values = [, null, undefined];const runs = [1, , , 2];const trailing = [1, 2,];let first, third;[first, , third] = colors;
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:sparse-array" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/ts:sparse-array] reason="..."

tx0 explain tx0/ts:sparse-array shows the same in the terminal. Found a false positive? Report it.