Skip to content

Commit

Permalink
no-unreadable-array-destructuring: Fix crash on destructuring in `f…
Browse files Browse the repository at this point in the history
…or…of` loop (#1076)
  • Loading branch information
fisker committed Jan 27, 2021
1 parent 172f116 commit 11ce1bc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions rules/no-unreadable-array-destructuring.js
Expand Up @@ -31,6 +31,7 @@ const create = context => {
if (
parent.type === 'VariableDeclarator' &&
parent.id === node &&
parent.init !== null &&
nonNullElements.length === 1
) {
const [element] = nonNullElements;
Expand Down
4 changes: 3 additions & 1 deletion test/integration/projects.js
Expand Up @@ -140,7 +140,9 @@ module.exports = [
// #903
'https://github.com/mattermost/mattermost-webapp',
// #1030
'https://github.com/astrofox-io/astrofox'
'https://github.com/astrofox-io/astrofox',
// #1075
'https://github.com/jaredLunde/masonic'
].map(project => {
if (typeof project === 'string') {
project = {repository: project};
Expand Down
3 changes: 2 additions & 1 deletion test/no-unreadable-array-destructuring.js
Expand Up @@ -47,6 +47,7 @@ test.snapshot({
// Multiple declarations
'let [,,thirdElement] = foo, anotherVariable = bar;',
// Default value
'let [,,thirdElement = {}] = foo;'
'let [,,thirdElement = {}] = foo;',
'for (const [, , id] of shuffle(list)) {}'
]
});
10 changes: 10 additions & 0 deletions test/snapshots/no-unreadable-array-destructuring.js.md
Expand Up @@ -270,3 +270,13 @@ Generated by [AVA](https://avajs.dev).
> 1 | let [,,thirdElement = {}] = foo;␊
| ^^^^^^^^^^^^^^^^^^^^^ Array destructuring may not contain consecutive ignored values.␊
`

## Invalid #21
1 | for (const [, , id] of shuffle(list)) {}

> Error 1/1
`␊
> 1 | for (const [, , id] of shuffle(list)) {}␊
| ^^^^^^^^ Array destructuring may not contain consecutive ignored values.␊
`
Binary file modified test/snapshots/no-unreadable-array-destructuring.js.snap
Binary file not shown.

0 comments on commit 11ce1bc

Please sign in to comment.