no-sparse-arrays
JavaScript / TypeScriptsuspiciousno fixdefault: warnjs/eslint-recommendedjs/biome-recommendedjs/oxlint
What it does
Section titled “What it does”Reports a hole in an array literal, at the extra comma: [1, , 2] and [, 1]. A single trailing comma ([1, ]) is not a hole.
Why it matters
Section titled “Why it matters”A hole is an index with no element. [1, , 2] has the length 3, and methods such as forEach and map skip the hole while for loops and spread read it as undefined, so the same array behaves differently depending on how it is read. It is nearly always a typo for a single comma.
To fix, remove the extra comma, or write undefined (or null) where a value is meant.
Example
Section titled “Example”...class K { static {} }...var x = [1, , 2, ,], y = [[], [,]];...Configuration
Section titled “Configuration”js: lint: rules: no-sparse-arrays: warn # off, warn (default), errorEnabled by the presets: js/eslint-recommended, js/biome-recommended, js/oxlint.
Suppress one line with sudsy-disable-next-line no-sparse-arrays in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| eslint | no-sparse-arrays |
full |