unicorn/no-unreadable-array-destructuring
Disallow array destructuring that skips two or more values in a row
In const [,,, year] = parts, you have to count commas to know which element you get, and it's easy to miss one comma too many or too few. Read the element by its index instead.
Skipping one value at a time is fine.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"unicorn/no-unreadable-array-destructuring" = "error" # or "warn"Examples#
example.js2 problems
const [, , , year]Array destructuring may not contain consecutive ignored values. = match;
function area([, , width, height]Array destructuring may not contain consecutive ignored values.) {
return width * height;
}example.jsNo problems
const year = match[3];
function area(box) {
return box[2] * box[3];
}
const [, month] = match;
const [first, , third] = match;