Skip to content

fix: no-sparse-arrays should not flag destructuring assignment targets#1242

Merged
fansenze merged 1 commit into
mainfrom
fix/no-sparse-arrays-destructuring
Jul 10, 2026
Merged

fix: no-sparse-arrays should not flag destructuring assignment targets#1242
fansenze merged 1 commit into
mainfrom
fix/no-sparse-arrays-destructuring

Conversation

@swwind

@swwind swwind commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

no-sparse-arrays was flagging destructuring assignment targets like [, suggestion] = await all() as sparse arrays. TypeScript's AST parses these as ArrayLiteralExpression (same node kind as real array literals), so omitted elements used to skip items during destructuring were incorrectly treated as sparse-array holes. ESLint's own rule only checks ArrayExpression nodes and never flags this, since espree gives destructuring targets a distinct ArrayPattern kind. Fixed by skipping nodes where ast.IsAssignmentTarget(node) is true, verified against real ESLint 8 output for both the valid destructuring cases and the still-invalid genuine sparse array literals.

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

TypeScript's AST parses destructuring assignment targets (e.g. `[, a] = b`)
as ArrayLiteralExpression, same as array literals, so omitted elements
used to skip items were misflagged as sparse arrays. Skip nodes that are
assignment targets, matching ESLint's behavior.
Copilot AI review requested due to automatic review settings July 9, 2026 09:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@fansenze fansenze enabled auto-merge (squash) July 9, 2026 09:32
@fansenze fansenze merged commit 5525655 into main Jul 10, 2026
24 of 26 checks passed
@fansenze fansenze deleted the fix/no-sparse-arrays-destructuring branch July 10, 2026 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants