Skip to content

Commit 8e00305

Browse files
docs: replace var with const in rule examples (#19299)
* docs: replace var with const in rule example * revert changes in no-else-block * replace var in no-empty-pattern
1 parent a559009 commit 8e00305

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

docs/src/rules/no-dupe-class-members.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Foo {
1515
bar() { console.log("goodbye"); }
1616
}
1717

18-
var foo = new Foo();
18+
const foo = new Foo();
1919
foo.bar(); // goodbye
2020
```
2121

docs/src/rules/no-dupe-keys.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ handled_by_typescript: true
99
Multiple properties with the same key in object literals can cause unexpected behavior in your application.
1010

1111
```js
12-
var foo = {
12+
const foo = {
1313
bar: "baz",
1414
bar: "qux"
1515
};
@@ -26,17 +26,17 @@ Examples of **incorrect** code for this rule:
2626
```js
2727
/*eslint no-dupe-keys: "error"*/
2828

29-
var foo = {
29+
const foo = {
3030
bar: "baz",
3131
bar: "qux"
3232
};
3333

34-
var foo = {
34+
const bar = {
3535
"bar": "baz",
3636
bar: "qux"
3737
};
3838

39-
var foo = {
39+
const baz = {
4040
0x1: "baz",
4141
1: "qux"
4242
};
@@ -51,7 +51,7 @@ Examples of **correct** code for this rule:
5151
```js
5252
/*eslint no-dupe-keys: "error"*/
5353

54-
var foo = {
54+
const foo = {
5555
bar: "baz",
5656
quxx: "qux"
5757
};

docs/src/rules/no-duplicate-case.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Examples of **incorrect** code for this rule:
1818
```js
1919
/*eslint no-duplicate-case: "error"*/
2020

21-
var a = 1,
21+
const a = 1,
2222
one = 1;
2323

2424
switch (a) {
@@ -64,7 +64,7 @@ Examples of **correct** code for this rule:
6464
```js
6565
/*eslint no-duplicate-case: "error"*/
6666

67-
var a = 1,
67+
const a = 1,
6868
one = 1;
6969

7070
switch (a) {

docs/src/rules/no-empty-character-class.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ rule_type: problem
88
Because empty character classes in regular expressions do not match anything, they might be typing mistakes.
99

1010
```js
11-
var foo = /^abc[]/;
11+
const foo = /^abc[]/;
1212
```
1313

1414
## Rule Details
@@ -73,5 +73,5 @@ Example of a *false negative* when this rule reports correct code:
7373
```js
7474
/*eslint no-empty-character-class: "error"*/
7575

76-
var abcNeverMatches = new RegExp("^abc[]");
76+
const abcNeverMatches = new RegExp("^abc[]");
7777
```

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