Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit93c325a

Browse files
docs: rewrite examples with var using let and const (#19398)
1 parent56ff404 commit93c325a

File tree

4 files changed

+37
-37
lines changed

4 files changed

+37
-37
lines changed

‎docs/src/rules/init-declarations.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ rule_type: suggestion
77
In JavaScript, variables can be assigned during declaration, or at any point afterwards using an assignment statement. For example, in the following code,`foo` is initialized during declaration, while`bar` is initialized later.
88

99
```js
10-
var foo=1;
11-
var bar;
10+
let foo=1;
11+
let bar;
1212

1313
if (foo) {
1414
bar=1;
@@ -22,8 +22,8 @@ if (foo) {
2222
This rule is aimed at enforcing or eliminating variable initializations during declaration. For example, in the following code,`foo` is initialized during declaration, while`bar` is not.
2323

2424
```js
25-
var foo=1;
26-
var bar;
25+
let foo=1;
26+
let bar;
2727

2828
bar=2;
2929
```
@@ -109,7 +109,7 @@ function foo() {
109109
var bar=1;
110110
let baz=2;
111111

112-
for (var i=0; i<1; i++) {}
112+
for (let i=0; i<1; i++) {}
113113
}
114114
```
115115

@@ -141,7 +141,7 @@ Examples of **correct** code for the `"never", { "ignoreForLoopInit": true }` op
141141

142142
```js
143143
/*eslint init-declarations: ["error", "never", { "ignoreForLoopInit": true }]*/
144-
for (var i=0; i<1; i++) {}
144+
for (let i=0; i<1; i++) {}
145145
```
146146

147147
:::

‎docs/src/rules/no-empty-function.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ Examples of **incorrect** code for this rule:
3737

3838
functionfoo() {}
3939

40-
varbar=function() {};
40+
constbar=function() {};
4141

42-
varbar= ()=> {};
42+
constbar1= ()=> {};
4343

4444
function*baz() {}
4545

46-
varbar=function*() {};
46+
constbar2=function*() {};
4747

48-
var obj= {
48+
constobj= {
4949
foo:function() {},
5050

5151
foo:function*() {},
@@ -93,23 +93,23 @@ function foo() {
9393
// do nothing.
9494
}
9595

96-
varbaz=function() {
96+
constbaz=function() {
9797
// any clear comments.
9898
};
9999

100-
varbaz= ()=> {
100+
constbaz1= ()=> {
101101
bar();
102102
};
103103

104104
function*foobar() {
105105
// do nothing.
106106
}
107107

108-
varbaz=function*() {
108+
constbaz2=function*() {
109109
// do nothing.
110110
};
111111

112-
var obj= {
112+
constobj= {
113113
foo:function() {
114114
// do nothing.
115115
},
@@ -203,9 +203,9 @@ Examples of **correct** code for the `{ "allow": ["functions"] }` option:
203203

204204
functionfoo() {}
205205

206-
varbar=function() {};
206+
constbar=function() {};
207207

208-
var obj= {
208+
constobj= {
209209
foo:function() {}
210210
};
211211
```
@@ -221,7 +221,7 @@ Examples of **correct** code for the `{ "allow": ["arrowFunctions"] }` option:
221221
```js
222222
/*eslint no-empty-function: ["error", { "allow": ["arrowFunctions"] }]*/
223223

224-
varfoo= ()=> {};
224+
constfoo= ()=> {};
225225
```
226226

227227
:::
@@ -237,9 +237,9 @@ Examples of **correct** code for the `{ "allow": ["generatorFunctions"] }` optio
237237

238238
function*foo() {}
239239

240-
varbar=function*() {};
240+
constbar=function*() {};
241241

242-
var obj= {
242+
constobj= {
243243
foo:function*() {}
244244
};
245245
```
@@ -255,7 +255,7 @@ Examples of **correct** code for the `{ "allow": ["methods"] }` option:
255255
```js
256256
/*eslint no-empty-function: ["error", { "allow": ["methods"] }]*/
257257

258-
var obj= {
258+
constobj= {
259259
foo() {}
260260
};
261261

@@ -276,7 +276,7 @@ Examples of **correct** code for the `{ "allow": ["generatorMethods"] }` option:
276276
```js
277277
/*eslint no-empty-function: ["error", { "allow": ["generatorMethods"] }]*/
278278

279-
var obj= {
279+
constobj= {
280280
*foo() {}
281281
};
282282

@@ -297,7 +297,7 @@ Examples of **correct** code for the `{ "allow": ["getters"] }` option:
297297
```js
298298
/*eslint no-empty-function: ["error", { "allow": ["getters"] }]*/
299299

300-
var obj= {
300+
constobj= {
301301
getfoo() {}
302302
};
303303

@@ -318,7 +318,7 @@ Examples of **correct** code for the `{ "allow": ["setters"] }` option:
318318
```js
319319
/*eslint no-empty-function: ["error", { "allow": ["setters"] }]*/
320320

321-
var obj= {
321+
constobj= {
322322
setfoo(value) {}
323323
};
324324

@@ -369,7 +369,7 @@ Examples of **correct** code for the `{ "allow": ["asyncMethods"] }` options:
369369
```js
370370
/*eslint no-empty-function: ["error", { "allow": ["asyncMethods"] }]*/
371371

372-
var obj= {
372+
constobj= {
373373
asyncfoo() {}
374374
};
375375

‎docs/src/rules/no-extra-boolean-cast.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ Examples of **incorrect** code for this rule:
3030
```js
3131
/*eslint no-extra-boolean-cast: "error"*/
3232

33-
var foo=!!!bar;
33+
constfoo=!!!bar;
3434

35-
var foo=!!bar? baz: bat;
35+
constfoo1=!!bar? baz: bat;
3636

37-
var foo=Boolean(!!bar);
37+
constfoo2=Boolean(!!bar);
3838

39-
var foo=newBoolean(!!bar);
39+
constfoo3=newBoolean(!!bar);
4040

4141
if (!!foo) {
4242
// ...
@@ -68,14 +68,14 @@ Examples of **correct** code for this rule:
6868
```js
6969
/*eslint no-extra-boolean-cast: "error"*/
7070

71-
var foo=!!bar;
72-
var foo=Boolean(bar);
71+
constfoo=!!bar;
72+
constfoo1=Boolean(bar);
7373

7474
functionqux() {
7575
return!!bar;
7676
}
7777

78-
varfoo= bar?!!baz:!!bat;
78+
foo= bar?!!baz:!!bat;
7979
```
8080

8181
:::
@@ -109,7 +109,7 @@ if ((!!foo || bar) && !!baz) {
109109
//...
110110
}
111111

112-
var foo=newBoolean(!!bar|| baz);
112+
constfoo=newBoolean(!!bar|| baz);
113113

114114
foo&&Boolean(bar)? baz: bat;
115115

@@ -134,9 +134,9 @@ Examples of **correct** code for this rule with `"enforceForInnerExpressions"` o
134134
```js
135135
/*eslint no-extra-boolean-cast: ["error", {"enforceForInnerExpressions": true}]*/
136136

137-
// Note that `||` and `&&` alone aren't a boolean context for either operand
137+
// Note that `||` and `&&` alone aren't a boolean context for either operand
138138
// since the resultant value need not be a boolean without casting.
139-
var foo=!!bar|| baz;
139+
constfoo=!!bar|| baz;
140140

141141
if (foo|| bar) {
142142
//...
@@ -150,7 +150,7 @@ if ((foo || bar) && baz) {
150150
//...
151151
}
152152

153-
var foo=newBoolean(bar|| baz);
153+
constfoo1=newBoolean(bar|| baz);
154154

155155
foo&& bar? baz: bat;
156156

‎docs/src/rules/no-restricted-properties.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Examples of **incorrect** code for this rule:
8181
"property": "disallowedPropertyName"
8282
}]*/
8383

84-
var example=disallowedObjectName.disallowedPropertyName;/*error Disallowed object property: disallowedObjectName.disallowedPropertyName.*/
84+
constexample=disallowedObjectName.disallowedPropertyName;/*error Disallowed object property: disallowedObjectName.disallowedPropertyName.*/
8585

8686
disallowedObjectName.disallowedPropertyName();/*error Disallowed object property: disallowedObjectName.disallowedPropertyName.*/
8787
```
@@ -126,7 +126,7 @@ Examples of **correct** code for this rule:
126126
"property": "disallowedPropertyName"
127127
}]*/
128128

129-
var example=disallowedObjectName.somePropertyName;
129+
constexample=disallowedObjectName.somePropertyName;
130130

131131
allowedObjectName.disallowedPropertyName();
132132
```

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp