Skip to content

Commit 069af5e

Browse files
authored
docs: rewrite var using const in rule examples (#19303)
1 parent 064e35d commit 069af5e

File tree

3 files changed

+42
-42
lines changed

3 files changed

+42
-42
lines changed

docs/src/rules/no-useless-computed-key.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ rule_type: suggestion
88
It's unnecessary to use computed properties with literals such as:
99

1010
```js
11-
var foo = {["a"]: "b"};
11+
const foo = {["a"]: "b"};
1212
```
1313

1414
The code can be rewritten as:
1515

1616
```js
17-
var foo = {"a": "b"};
17+
const foo = {"a": "b"};
1818
```
1919

2020
## Rule Details
@@ -28,14 +28,14 @@ Examples of **incorrect** code for this rule:
2828
```js
2929
/*eslint no-useless-computed-key: "error"*/
3030

31-
var a = { ['0']: 0 };
32-
var a = { ['0+1,234']: 0 };
33-
var a = { [0]: 0 };
34-
var a = { ['x']: 0 };
35-
var a = { ['x']() {} };
31+
const a = { ['0']: 0 };
32+
const b = { ['0+1,234']: 0 };
33+
const c = { [0]: 0 };
34+
const d = { ['x']: 0 };
35+
const e = { ['x']() {} };
3636

37-
var { [0]: a } = obj;
38-
var { ['x']: a } = obj;
37+
const { [0]: foo } = obj;
38+
const { ['x']: bar } = obj;
3939

4040
class Foo {
4141
["foo"] = "bar";
@@ -60,14 +60,14 @@ Examples of **correct** code for this rule:
6060
```js
6161
/*eslint no-useless-computed-key: "error"*/
6262

63-
var c = { 'a': 0 };
64-
var c = { 0: 0 };
65-
var a = { x() {} };
66-
var c = { a: 0 };
67-
var c = { '0+1,234': 0 };
63+
const a = { 'a': 0 };
64+
const b = { 0: 0 };
65+
const c = { x() {} };
66+
const d = { a: 0 };
67+
const e = { '0+1,234': 0 };
6868

69-
var { 0: a } = obj;
70-
var { 'x': a } = obj;
69+
const { 0: foo } = obj;
70+
const { 'x': bar } = obj;
7171

7272
class Foo {
7373
"foo" = "bar";
@@ -92,7 +92,7 @@ Examples of additional **correct** code for this rule:
9292
```js
9393
/*eslint no-useless-computed-key: "error"*/
9494

95-
var c = {
95+
const c = {
9696
"__proto__": foo, // defines object's prototype
9797

9898
["__proto__"]: bar // defines a property named "__proto__"

docs/src/rules/no-useless-concat.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ rule_type: suggestion
77
It's unnecessary to concatenate two strings together, such as:
88

99
```js
10-
var foo = "a" + "b";
10+
const foo = "a" + "b";
1111
```
1212

1313
This code is likely the result of refactoring where a variable was removed from the concatenation (such as `"a" + b + "b"`). In such a case, the concatenation isn't important and the code can be rewritten as:
1414

1515
```js
16-
var foo = "ab";
16+
const foo = "ab";
1717
```
1818

1919
## Rule Details
@@ -27,13 +27,13 @@ Examples of **incorrect** code for this rule:
2727
```js
2828
/*eslint no-useless-concat: "error"*/
2929

30-
var a = `some` + `string`;
30+
const a = `some` + `string`;
3131

3232
// these are the same as "10"
33-
var a = '1' + '0';
34-
var a = '1' + `0`;
35-
var a = `1` + '0';
36-
var a = `1` + `0`;
33+
const b = '1' + '0';
34+
const c = '1' + `0`;
35+
const d = `1` + '0';
36+
const e = `1` + `0`;
3737
```
3838

3939
:::
@@ -46,12 +46,12 @@ Examples of **correct** code for this rule:
4646
/*eslint no-useless-concat: "error"*/
4747

4848
// when a non string is included
49-
var c = a + b;
50-
var c = '1' + a;
51-
var a = 1 + '1';
52-
var c = 1 - 2;
49+
const a = a + b;
50+
const b = '1' + a;
51+
const c = 1 + '1';
52+
const d = 1 - 2;
5353
// when the string concatenation is multiline
54-
var c = "foo" +
54+
const e = "foo" +
5555
"bar";
5656
```
5757

docs/src/rules/no-useless-return.md

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

21-
var foo = function() { return; }
21+
const foo = function() { return; }
2222

23-
var foo = function() {
23+
const bar = function() {
2424
doSomething();
2525
return;
2626
}
2727

28-
var foo = function() {
28+
const baz = function() {
2929
if (condition) {
30-
bar();
30+
qux();
3131
return;
3232
} else {
33-
baz();
33+
quux();
3434
}
3535
}
3636

37-
var foo = function() {
37+
const item = function() {
3838
switch (bar) {
3939
case 1:
4040
doSomething();
@@ -55,23 +55,23 @@ Examples of **correct** code for this rule:
5555
```js
5656
/* eslint no-useless-return: "error" */
5757

58-
var foo = function() { return 5; }
58+
const foo = function() { return 5; }
5959

60-
var foo = function() {
60+
const bar = function() {
6161
return doSomething();
6262
}
6363

64-
var foo = function() {
64+
const baz = function() {
6565
if (condition) {
66-
bar();
66+
qux();
6767
return;
6868
} else {
69-
baz();
69+
quux();
7070
}
7171
qux();
7272
}
7373

74-
var foo = function() {
74+
const item = function() {
7575
switch (bar) {
7676
case 1:
7777
doSomething();
@@ -81,7 +81,7 @@ var foo = function() {
8181
}
8282
}
8383

84-
var foo = function() {
84+
const func = function() {
8585
for (const foo of bar) {
8686
return;
8787
}

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