Skip to content

Commit b7012c8

Browse files
docs: rewrite examples with var using let and const (#19407)
1 parent d4c47c3 commit b7012c8

File tree

5 files changed

+60
-60
lines changed

5 files changed

+60
-60
lines changed

docs/src/rules/func-names.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Examples of **correct** code for this rule with the `"as-needed"` option:
113113
```js
114114
/*eslint func-names: ["error", "as-needed"]*/
115115

116-
var bar = function() {};
116+
const bar = function() {};
117117

118118
const cat = {
119119
meow: function() {}
@@ -192,7 +192,7 @@ Examples of **correct** code for this rule with the `"always", { "generators": "
192192
```js
193193
/*eslint func-names: ["error", "always", { "generators": "as-needed" }]*/
194194

195-
var foo = function*() {};
195+
const foo = function*() {};
196196
```
197197
198198
:::
@@ -204,7 +204,7 @@ Examples of **incorrect** code for this rule with the `"always", { "generators":
204204
```js
205205
/*eslint func-names: ["error", "always", { "generators": "never" }]*/
206206

207-
var foo = bar(function *baz() {});
207+
const foo = bar(function *baz() {});
208208
```
209209
210210
:::
@@ -216,7 +216,7 @@ Examples of **correct** code for this rule with the `"always", { "generators": "
216216
```js
217217
/*eslint func-names: ["error", "always", { "generators": "never" }]*/
218218

219-
var foo = bar(function *() {});
219+
const foo = bar(function *() {});
220220
```
221221
222222
:::
@@ -228,7 +228,7 @@ Examples of **incorrect** code for this rule with the `"as-needed", { "generator
228228
```js
229229
/*eslint func-names: ["error", "as-needed", { "generators": "never" }]*/
230230

231-
var foo = bar(function *baz() {});
231+
const foo = bar(function *baz() {});
232232
```
233233
234234
:::
@@ -240,7 +240,7 @@ Examples of **correct** code for this rule with the `"as-needed", { "generators"
240240
```js
241241
/*eslint func-names: ["error", "as-needed", { "generators": "never" }]*/
242242

243-
var foo = bar(function *() {});
243+
const foo = bar(function *() {});
244244
```
245245
246246
:::
@@ -252,7 +252,7 @@ Examples of **incorrect** code for this rule with the `"never", { "generators":
252252
```js
253253
/*eslint func-names: ["error", "never", { "generators": "always" }]*/
254254

255-
var foo = bar(function *() {});
255+
const foo = bar(function *() {});
256256
```
257257
258258
:::
@@ -264,7 +264,7 @@ Examples of **correct** code for this rule with the `"never", { "generators": "a
264264
```js
265265
/*eslint func-names: ["error", "never", { "generators": "always" }]*/
266266

267-
var foo = bar(function *baz() {});
267+
const foo = bar(function *baz() {});
268268
```
269269
270270
:::

docs/src/rules/func-style.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ For function expressions, you must define the function before it is used, otherw
3939
```js
4040
doSomething(); // error!
4141

42-
var doSomething = function() {
42+
const doSomething = function() {
4343
// ...
4444
};
4545
```
@@ -93,11 +93,11 @@ Examples of **correct** code for this rule with the default `"expression"` optio
9393
```js
9494
/*eslint func-style: ["error", "expression"]*/
9595

96-
var foo = function() {
96+
const foo = function() {
9797
// ...
9898
};
9999

100-
var foo = () => {};
100+
const foo1 = () => {};
101101

102102
// allowed as allowArrowFunctions : false is applied only for declaration
103103
```
@@ -113,11 +113,11 @@ Examples of **incorrect** code for this rule with the `"declaration"` option:
113113
```js
114114
/*eslint func-style: ["error", "declaration"]*/
115115

116-
var foo = function() {
116+
const foo = function() {
117117
// ...
118118
};
119119

120-
var foo = () => {};
120+
const foo1 = () => {};
121121
```
122122

123123
:::
@@ -150,7 +150,7 @@ Examples of additional **correct** code for this rule with the `"declaration", {
150150
```js
151151
/*eslint func-style: ["error", "declaration", { "allowArrowFunctions": true }]*/
152152

153-
var foo = () => {};
153+
const foo = () => {};
154154
```
155155

156156
:::
@@ -182,11 +182,11 @@ Examples of **correct** code for this rule with the `"declaration"` and `{"overr
182182
```js
183183
/*eslint func-style: ["error", "declaration", { "overrides": { "namedExports": "expression" } }]*/
184184

185-
export var foo = function() {
185+
export const foo = function() {
186186
// ...
187187
};
188188

189-
export var bar = () => {};
189+
export const bar = () => {};
190190
```
191191

192192
:::
@@ -200,11 +200,11 @@ Examples of **incorrect** code for this rule with the `"expression"` and `{"over
200200
```js
201201
/*eslint func-style: ["error", "expression", { "overrides": { "namedExports": "declaration" } }]*/
202202

203-
export var foo = function() {
203+
export const foo = function() {
204204
// ...
205205
};
206206

207-
export var bar = () => {};
207+
export const bar = () => {};
208208
```
209209

210210
:::
@@ -232,11 +232,11 @@ Examples of **correct** code for this rule with the `{"overrides": { "namedExpor
232232
```js
233233
/*eslint func-style: ["error", "expression", { "overrides": { "namedExports": "ignore" } }]*/
234234

235-
export var foo = function() {
235+
export const foo = function() {
236236
// ...
237237
};
238238

239-
export var bar = () => {};
239+
export const bar = () => {};
240240

241241
export function baz() {
242242
// ...

docs/src/rules/grouped-accessor-pairs.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ A getter and setter for the same property don't necessarily have to be defined a
1717
For example, the following statements would create the same object:
1818

1919
```js
20-
var o = {
20+
const o = {
2121
get a() {
2222
return this.val;
2323
},
@@ -27,7 +27,7 @@ var o = {
2727
b: 1
2828
};
2929

30-
var o = {
30+
const o1 = {
3131
get a() {
3232
return this.val;
3333
},
@@ -57,7 +57,7 @@ Examples of **incorrect** code for this rule:
5757
```js
5858
/*eslint grouped-accessor-pairs: "error"*/
5959

60-
var foo = {
60+
const foo = {
6161
get a() {
6262
return this.val;
6363
},
@@ -67,7 +67,7 @@ var foo = {
6767
}
6868
};
6969

70-
var bar = {
70+
const bar = {
7171
set b(value) {
7272
this.val = value;
7373
},
@@ -107,7 +107,7 @@ Examples of **correct** code for this rule:
107107
```js
108108
/*eslint grouped-accessor-pairs: "error"*/
109109

110-
var foo = {
110+
const foo = {
111111
get a() {
112112
return this.val;
113113
},
@@ -117,7 +117,7 @@ var foo = {
117117
b: 1
118118
};
119119

120-
var bar = {
120+
const bar = {
121121
set b(value) {
122122
this.val = value;
123123
},
@@ -167,7 +167,7 @@ Examples of **incorrect** code for this rule with the `"getBeforeSet"` option:
167167
```js
168168
/*eslint grouped-accessor-pairs: ["error", "getBeforeSet"]*/
169169

170-
var foo = {
170+
const foo = {
171171
set a(value) {
172172
this.val = value;
173173
},
@@ -204,7 +204,7 @@ Examples of **correct** code for this rule with the `"getBeforeSet"` option:
204204
```js
205205
/*eslint grouped-accessor-pairs: ["error", "getBeforeSet"]*/
206206

207-
var foo = {
207+
const foo = {
208208
get a() {
209209
return this.val;
210210
},
@@ -243,7 +243,7 @@ Examples of **incorrect** code for this rule with the `"setBeforeGet"` option:
243243
```js
244244
/*eslint grouped-accessor-pairs: ["error", "setBeforeGet"]*/
245245

246-
var foo = {
246+
const foo = {
247247
get a() {
248248
return this.val;
249249
},
@@ -280,7 +280,7 @@ Examples of **correct** code for this rule with the `"setBeforeGet"` option:
280280
```js
281281
/*eslint grouped-accessor-pairs: ["error", "setBeforeGet"]*/
282282

283-
var foo = {
283+
const foo = {
284284
set a(value) {
285285
this.val = value;
286286
},
@@ -318,10 +318,10 @@ might require or miss to require grouping or order for getters/setters that have
318318
```js
319319
/*eslint grouped-accessor-pairs: "error"*/
320320

321-
var a = 1;
321+
let a = 1;
322322

323323
// false warning (false positive)
324-
var foo = {
324+
const foo = {
325325
get [a++]() {
326326
return this.val;
327327
},
@@ -332,7 +332,7 @@ var foo = {
332332
};
333333

334334
// missed warning (false negative)
335-
var bar = {
335+
const bar = {
336336
get [++a]() {
337337
return this.val;
338338
},

docs/src/rules/max-lines-per-function.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Examples of **incorrect** code for this rule with a particular max value:
7979
```js
8080
/*eslint max-lines-per-function: ["error", 2]*/
8181
function foo() {
82-
var x = 0;
82+
const x = 0;
8383
}
8484
```
8585

@@ -91,7 +91,7 @@ function foo() {
9191
/*eslint max-lines-per-function: ["error", 3]*/
9292
function foo() {
9393
// a comment
94-
var x = 0;
94+
const x = 0;
9595
}
9696
```
9797

@@ -104,7 +104,7 @@ function foo() {
104104
function foo() {
105105
// a comment followed by a blank line
106106

107-
var x = 0;
107+
const x = 0;
108108
}
109109
```
110110

@@ -117,7 +117,7 @@ Examples of **correct** code for this rule with a particular max value:
117117
```js
118118
/*eslint max-lines-per-function: ["error", 3]*/
119119
function foo() {
120-
var x = 0;
120+
const x = 0;
121121
}
122122
```
123123

@@ -129,7 +129,7 @@ function foo() {
129129
/*eslint max-lines-per-function: ["error", 4]*/
130130
function foo() {
131131
// a comment
132-
var x = 0;
132+
const x = 0;
133133
}
134134
```
135135

@@ -142,7 +142,7 @@ function foo() {
142142
function foo() {
143143
// a comment followed by a blank line
144144

145-
var x = 0;
145+
const x = 0;
146146
}
147147
```
148148

@@ -158,7 +158,7 @@ Examples of **incorrect** code for this rule with the `{ "skipBlankLines": true
158158
/*eslint max-lines-per-function: ["error", {"max": 2, "skipBlankLines": true}]*/
159159
function foo() {
160160

161-
var x = 0;
161+
const x = 0;
162162
}
163163
```
164164

@@ -172,7 +172,7 @@ Examples of **correct** code for this rule with the `{ "skipBlankLines": true }`
172172
/*eslint max-lines-per-function: ["error", {"max": 3, "skipBlankLines": true}]*/
173173
function foo() {
174174

175-
var x = 0;
175+
const x = 0;
176176
}
177177
```
178178

@@ -188,7 +188,7 @@ Examples of **incorrect** code for this rule with the `{ "skipComments": true }`
188188
/*eslint max-lines-per-function: ["error", {"max": 2, "skipComments": true}]*/
189189
function foo() {
190190
// a comment
191-
var x = 0;
191+
const x = 0;
192192
}
193193
```
194194

@@ -202,7 +202,7 @@ Examples of **correct** code for this rule with the `{ "skipComments": true }` o
202202
/*eslint max-lines-per-function: ["error", {"max": 3, "skipComments": true}]*/
203203
function foo() {
204204
// a comment
205-
var x = 0;
205+
const x = 0;
206206
}
207207
```
208208

@@ -217,11 +217,11 @@ Examples of **incorrect** code for this rule with the `{ "IIFEs": true }` option
217217
```js
218218
/*eslint max-lines-per-function: ["error", {"max": 2, "IIFEs": true}]*/
219219
(function(){
220-
var x = 0;
220+
const x = 0;
221221
}());
222222

223223
(() => {
224-
var x = 0;
224+
const x = 0;
225225
})();
226226
```
227227

@@ -234,11 +234,11 @@ Examples of **correct** code for this rule with the `{ "IIFEs": true }` option:
234234
```js
235235
/*eslint max-lines-per-function: ["error", {"max": 3, "IIFEs": true}]*/
236236
(function(){
237-
var x = 0;
237+
const x = 0;
238238
}());
239239

240240
(() => {
241-
var x = 0;
241+
const x = 0;
242242
})();
243243
```
244244

0 commit comments

Comments
 (0)