mirror of
https://git.proxmox.com/git/pve-eslint
synced 2025-10-05 11:05:16 +00:00

includes a (minimal) working wrapper Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
55 lines
1.4 KiB
Markdown
55 lines
1.4 KiB
Markdown
# Disallow empty destructuring patterns (no-empty-pattern)
|
|
|
|
When using destructuring, it's possible to create a pattern that has no effect. This happens when empty curly braces are used to the right of an embedded object destructuring pattern, such as:
|
|
|
|
```js
|
|
// doesn't create any variables
|
|
var {a: {}} = foo;
|
|
```
|
|
|
|
In this code, no new variables are created because `a` is just a location helper while the `{}` is expected to contain the variables to create, such as:
|
|
|
|
```js
|
|
// creates variable b
|
|
var {a: { b }} = foo;
|
|
```
|
|
|
|
In many cases, the empty object pattern is a mistake where the author intended to use a default value instead, such as:
|
|
|
|
```js
|
|
// creates variable a
|
|
var {a = {}} = foo;
|
|
```
|
|
|
|
The difference between these two patterns is subtle, especially because the problematic empty pattern looks just like an object literal.
|
|
|
|
## Rule Details
|
|
|
|
This rule aims to flag any empty patterns in destructured objects and arrays, and as such, will report a problem whenever one is encountered.
|
|
|
|
Examples of **incorrect** code for this rule:
|
|
|
|
```js
|
|
/*eslint no-empty-pattern: "error"*/
|
|
|
|
var {} = foo;
|
|
var [] = foo;
|
|
var {a: {}} = foo;
|
|
var {a: []} = foo;
|
|
function foo({}) {}
|
|
function foo([]) {}
|
|
function foo({a: {}}) {}
|
|
function foo({a: []}) {}
|
|
```
|
|
|
|
Examples of **correct** code for this rule:
|
|
|
|
```js
|
|
/*eslint no-empty-pattern: "error"*/
|
|
|
|
var {a = {}} = foo;
|
|
var {a = []} = foo;
|
|
function foo({a = {}}) {}
|
|
function foo({a = []}) {}
|
|
```
|