Skip to content

Latest commit

Β 

History

History
71 lines (53 loc) Β· 1.29 KB

File metadata and controls

71 lines (53 loc) Β· 1.29 KB

no-unreadable-array-destructuring

πŸ“ Disallow unreadable array destructuring.

πŸ’Ό This rule is enabled in the following configs: βœ… recommended, β˜‘οΈ unopinionated.

πŸ”§ 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.

Examples

// βœ…
const [foo] = parts;
// βœ…
const [, foo] = parts;
// ❌
const [,, foo] = parts;

// βœ…
const foo = parts[2];
// ❌
const [,,, foo] = parts;

// βœ…
const foo = parts[3];
// βœ…
const [,...rest] = parts;
// ❌
const [,,...rest] = parts;

// βœ…
const rest = parts.slice(2);

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
			}
		]
	}
}