Skip to content

Latest commit

 

History

History
68 lines (50 loc) · 1.2 KB

no-unreadable-array-destructuring.md

File metadata and controls

68 lines (50 loc) · 1.2 KB

Disallow unreadable array destructuring

💼 This rule is enabled in the ✅ recommended config.

🔧 This rule is automatically fixable by the --fix CLI option.

Destructuring is very useful, but it can also make some code harder to read. This rule prevents ignoring consecutive values when destructuring from an array.

Fail

const [,, foo] = parts;
const [,,, foo] = parts;
const [,,,, foo] = parts;
const [,,...rest] = parts;

Pass

const [, foo] = parts;
const [foo] = parts;
const foo = parts[3];
const [,...rest] = parts;
const foo = parts.slice(3);

Note

You might have to modify the built-in prefer-destructuring rule to be compatible with this one:

{
	"rules": {
		"prefer-destructuring": [
			"error",
			{
				"object": true,
				"array": false
			}
		]
	}
}