Skip to content

Commit a58aa20

Browse files
authored
docs: fix examples for several rules (#17645)
1 parent 179929b commit a58aa20

9 files changed

+157
-69
lines changed

docs/src/rules/arrow-body-style.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Examples of **incorrect** code for this rule with the `"always"` option:
3232
```js
3333
/*eslint arrow-body-style: ["error", "always"]*/
3434
/*eslint-env es6*/
35+
3536
let foo = () => 0;
3637
```
3738

@@ -42,6 +43,9 @@ Examples of **correct** code for this rule with the `"always"` option:
4243
:::correct
4344

4445
```js
46+
/*eslint arrow-body-style: ["error", "always"]*/
47+
/*eslint-env es6*/
48+
4549
let foo = () => {
4650
return 0;
4751
};

docs/src/rules/function-paren-newline.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,15 @@ var barbaz = function(
339339
bar, baz
340340
) {};
341341

342-
var barbaz = (bar,
343-
baz) => {};
342+
var barbaz = (
343+
bar,
344+
baz
345+
) => {};
344346

345-
foo(bar,
346-
baz);
347+
foo(
348+
bar,
349+
baz
350+
);
347351
```
348352

349353
:::

docs/src/rules/id-match.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Examples of **correct** code for this rule with the `"^[a-z]+([A-Z][a-z]+)*$", {
143143
```js
144144
/*eslint id-match: [2, "^[a-z]+([A-Z][a-z]+)*$", { "onlyDeclarations": true }]*/
145145

146-
do_something(__dirname);
146+
foo = __dirname;
147147
```
148148

149149
:::

docs/src/rules/indent.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Examples of **correct** code for this rule with the `4, { "ignoredNodes": ["Call
192192
foo();
193193
bar();
194194

195-
})
195+
})();
196196
```
197197

198198
:::
@@ -403,7 +403,7 @@ function foo(x) {
403403
})();
404404

405405
if (y) {
406-
console.log('foo');
406+
console.log('foo');
407407
}
408408
```
409409

docs/src/rules/lines-around-directive.md

Lines changed: 112 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,8 @@ Examples of **incorrect** code for this rule with the `"always"` option:
6565
```js
6666
/* eslint lines-around-directive: ["error", "always"] */
6767

68-
/* Top of file */
69-
"use strict";
70-
var foo;
71-
72-
/* Top of file */
7368
// comment
7469
"use strict";
75-
"use asm";
7670
var foo;
7771

7872
function foo() {
@@ -90,23 +84,29 @@ function foo() {
9084

9185
:::
9286

93-
Examples of **correct** code for this rule with the `"always"` option:
94-
95-
::: correct { "sourceType": "script" }
87+
::: incorrect { "sourceType": "script" }
9688

9789
```js
9890
/* eslint lines-around-directive: ["error", "always"] */
9991

100-
/* Top of file */
92+
// comment
10193
"use strict";
102-
94+
"use asm";
10395
var foo;
96+
```
97+
98+
:::
99+
100+
Examples of **correct** code for this rule with the `"always"` option:
101+
102+
::: correct { "sourceType": "script" }
103+
104+
```js
105+
/* eslint lines-around-directive: ["error", "always"] */
104106

105-
/* Top of file */
106107
// comment
107108

108109
"use strict";
109-
"use asm";
110110

111111
var foo;
112112

@@ -128,6 +128,21 @@ function foo() {
128128

129129
:::
130130

131+
::: correct { "sourceType": "script" }
132+
133+
```js
134+
/* eslint lines-around-directive: ["error", "always"] */
135+
136+
// comment
137+
138+
"use strict";
139+
"use asm";
140+
141+
var foo;
142+
```
143+
144+
:::
145+
131146
### never
132147

133148
Examples of **incorrect** code for this rule with the `"never"` option:
@@ -137,17 +152,9 @@ Examples of **incorrect** code for this rule with the `"never"` option:
137152
```js
138153
/* eslint lines-around-directive: ["error", "never"] */
139154

140-
/* Top of file */
141-
142-
"use strict";
143-
144-
var foo;
145-
146-
/* Top of file */
147155
// comment
148156

149157
"use strict";
150-
"use asm";
151158

152159
var foo;
153160

@@ -169,21 +176,30 @@ function foo() {
169176

170177
:::
171178

172-
Examples of **correct** code for this rule with the `"never"` option:
173-
174-
::: correct { "sourceType": "script" }
179+
::: incorrect { "sourceType": "script" }
175180

176181
```js
177182
/* eslint lines-around-directive: ["error", "never"] */
178183

179-
/* Top of file */
184+
// comment
185+
180186
"use strict";
187+
"use asm";
188+
181189
var foo;
190+
```
191+
192+
:::
193+
194+
Examples of **correct** code for this rule with the `"never"` option:
195+
196+
::: correct { "sourceType": "script" }
197+
198+
```js
199+
/* eslint lines-around-directive: ["error", "never"] */
182200

183-
/* Top of file */
184201
// comment
185202
"use strict";
186-
"use asm";
187203
var foo;
188204

189205
function foo() {
@@ -201,6 +217,19 @@ function foo() {
201217

202218
:::
203219

220+
::: correct { "sourceType": "script" }
221+
222+
```js
223+
/* eslint lines-around-directive: ["error", "never"] */
224+
225+
// comment
226+
"use strict";
227+
"use asm";
228+
var foo;
229+
```
230+
231+
:::
232+
204233
### before & after
205234

206235
Examples of **incorrect** code for this rule with the `{ "before": "never", "after": "always" }` option:
@@ -210,16 +239,9 @@ Examples of **incorrect** code for this rule with the `{ "before": "never", "aft
210239
```js
211240
/* eslint lines-around-directive: ["error", { "before": "never", "after": "always" }] */
212241

213-
/* Top of file */
214-
215-
"use strict";
216-
var foo;
217-
218-
/* Top of file */
219242
// comment
220243

221244
"use strict";
222-
"use asm";
223245
var foo;
224246

225247
function foo() {
@@ -238,22 +260,29 @@ function foo() {
238260

239261
:::
240262

241-
Examples of **correct** code for this rule with the `{ "before": "never", "after": "always" }` option:
242-
243-
::: correct { "sourceType": "script" }
263+
::: incorrect { "sourceType": "script" }
244264

245265
```js
246266
/* eslint lines-around-directive: ["error", { "before": "never", "after": "always" }] */
247267

248-
/* Top of file */
249-
"use strict";
268+
// comment
250269

270+
"use strict";
271+
"use asm";
251272
var foo;
273+
```
274+
275+
:::
276+
277+
Examples of **correct** code for this rule with the `{ "before": "never", "after": "always" }` option:
278+
279+
::: correct { "sourceType": "script" }
280+
281+
```js
282+
/* eslint lines-around-directive: ["error", { "before": "never", "after": "always" }] */
252283

253-
/* Top of file */
254284
// comment
255285
"use strict";
256-
"use asm";
257286

258287
var foo;
259288

@@ -274,22 +303,29 @@ function foo() {
274303

275304
:::
276305

277-
Examples of **incorrect** code for this rule with the `{ "before": "always", "after": "never" }` option:
278-
279-
::: incorrect { "sourceType": "script" }
306+
::: correct { "sourceType": "script" }
280307

281308
```js
282-
/* eslint lines-around-directive: ["error", { "before": "always", "after": "never" }] */
309+
/* eslint lines-around-directive: ["error", { "before": "never", "after": "always" }] */
283310

284-
/* Top of file */
311+
// comment
285312
"use strict";
313+
"use asm";
286314

287315
var foo;
316+
```
317+
318+
:::
319+
320+
Examples of **incorrect** code for this rule with the `{ "before": "always", "after": "never" }` option:
321+
322+
::: incorrect { "sourceType": "script" }
323+
324+
```js
325+
/* eslint lines-around-directive: ["error", { "before": "always", "after": "never" }] */
288326

289-
/* Top of file */
290327
// comment
291328
"use strict";
292-
"use asm";
293329

294330
var foo;
295331

@@ -310,22 +346,30 @@ function foo() {
310346

311347
:::
312348

313-
Examples of **correct** code for this rule with the `{ "before": "always", "after": "never" }` option:
314-
315-
::: correct { "sourceType": "script" }
349+
::: incorrect { "sourceType": "script" }
316350

317351
```js
318352
/* eslint lines-around-directive: ["error", { "before": "always", "after": "never" }] */
319353

320-
/* Top of file */
354+
// comment
321355
"use strict";
356+
"use asm";
357+
322358
var foo;
359+
```
360+
361+
:::
362+
363+
Examples of **correct** code for this rule with the `{ "before": "always", "after": "never" }` option:
364+
365+
::: correct { "sourceType": "script" }
366+
367+
```js
368+
/* eslint lines-around-directive: ["error", { "before": "always", "after": "never" }] */
323369

324-
/* Top of file */
325370
// comment
326371

327372
"use strict";
328-
"use asm";
329373
var foo;
330374

331375
function foo() {
@@ -344,6 +388,20 @@ function foo() {
344388

345389
:::
346390

391+
::: correct { "sourceType": "script" }
392+
393+
```js
394+
/* eslint lines-around-directive: ["error", { "before": "always", "after": "never" }] */
395+
396+
// comment
397+
398+
"use strict";
399+
"use asm";
400+
var foo;
401+
```
402+
403+
:::
404+
347405
## When Not To Use It
348406

349407
You can safely disable this rule if you do not have any strict conventions about whether or not directive prologues should have blank newlines before or after them.

docs/src/rules/max-statements-per-line.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ if (condition) { bar = 1; } else { baz = 2; }
7676
for (var i = 0; i < length; ++i) { bar = 1; baz = 2; }
7777
switch (discriminant) { case 'test': break; default: break; }
7878
function foo() { bar = 1; baz = 2; }
79-
var qux = function qux() { bar = 1; };
79+
var qux = function qux() { bar = 1; baz = 2; };
8080
(function foo() { bar = 1; baz = 2; })();
8181
```
8282

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