Skip to content

Commit 0b48067

Browse files
replace var in no-empty-pattern
1 parent e1dd9f7 commit 0b48067

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

docs/src/rules/no-empty-pattern.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ When using destructuring, it's possible to create a pattern that has no effect.
99

1010
```js
1111
// doesn't create any variables
12-
var {a: {}} = foo;
12+
const {a: {}} = foo;
1313
```
1414

1515
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:
1616

1717
```js
1818
// creates variable b
19-
var {a: { b }} = foo;
19+
const {a: { b }} = foo;
2020
```
2121

2222
In many cases, the empty object pattern is a mistake where the author intended to use a default value instead, such as:
2323

2424
```js
2525
// creates variable a
26-
var {a = {}} = foo;
26+
const {a = {}} = foo;
2727
```
2828

2929
The difference between these two patterns is subtle, especially because the problematic empty pattern looks just like an object literal.
@@ -39,10 +39,10 @@ Examples of **incorrect** code for this rule:
3939
```js
4040
/*eslint no-empty-pattern: "error"*/
4141

42-
var {} = foo;
43-
var [] = foo;
44-
var {a: {}} = foo;
45-
var {a: []} = foo;
42+
const {} = foo;
43+
const [] = foo;
44+
const {a: {}} = foo;
45+
const {a: []} = foo;
4646
function foo({}) {}
4747
function bar([]) {}
4848
function baz({a: {}}) {}
@@ -58,8 +58,8 @@ Examples of **correct** code for this rule:
5858
```js
5959
/*eslint no-empty-pattern: "error"*/
6060

61-
var {a = {}} = foo;
62-
var {a = []} = foo;
61+
const {a = {}} = foo;
62+
const {b = []} = foo;
6363
function foo({a = {}}) {}
6464
function bar({a = []}) {}
6565
```
@@ -84,10 +84,10 @@ Examples of **incorrect** code for this rule with the `{"allowObjectPatternsAsPa
8484
/*eslint no-empty-pattern: ["error", { "allowObjectPatternsAsParameters": true }]*/
8585

8686
function foo({a: {}}) {}
87-
var bar = function({a: {}}) {};
88-
var bar = ({a: {}}) => {};
89-
var bar = ({} = bar) => {};
90-
var bar = ({} = { bar: 1 }) => {};
87+
const bar = function({a: {}}) {};
88+
const qux = ({a: {}}) => {};
89+
const quux = ({} = bar) => {};
90+
const item = ({} = { bar: 1 }) => {};
9191

9292
function baz([]) {}
9393
```
@@ -102,8 +102,8 @@ Examples of **correct** code for this rule with the `{"allowObjectPatternsAsPara
102102
/*eslint no-empty-pattern: ["error", { "allowObjectPatternsAsParameters": true }]*/
103103

104104
function foo({}) {}
105-
var bar = function({}) {};
106-
var bar = ({}) => {};
105+
const bar = function({}) {};
106+
const qux = ({}) => {};
107107

108108
function baz({} = {}) {}
109109
```

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy