Skip to content

Commit ee5be81

Browse files
authored
docs: default to sourceType: "module" in rule examples (#17615)
* Default to `"sourceType": "module"` in rule examples * Fix `sourceType` in obvious cases * Fix `sourceType` in less obvious cases * Fix name conflicts * Apply suggestions
1 parent dd79abc commit ee5be81

53 files changed

Lines changed: 296 additions & 301 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/.eleventy.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,12 @@ module.exports = function(eleventyConfig) {
205205
}
206206

207207
// See https://github.com/eslint/eslint.org/blob/ac38ab41f99b89a8798d374f74e2cce01171be8b/src/playground/App.js#L44
208-
const parserOptions = tokens[index].info?.split("correct ")[1]?.trim();
208+
const parserOptionsJSON = tokens[index].info?.split("correct ")[1]?.trim();
209+
const parserOptions = { sourceType: "module", ...(parserOptionsJSON && JSON.parse(parserOptionsJSON)) };
209210
const { content } = tokens[index + 1];
210211
const state = encodeToBase64(
211212
JSON.stringify({
212-
...(parserOptions && { options: { parserOptions: JSON.parse(parserOptions) } }),
213+
options: { parserOptions },
213214
text: content
214215
})
215216
);

docs/src/rules/camelcase.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ function UNSAFE_componentWillMount() {
328328
// ...
329329
}
330330

331-
function UNSAFE_componentWillMount() {
331+
function UNSAFE_componentWillReceiveProps() {
332332
// ...
333333
}
334334
```

docs/src/rules/comma-spacing.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ var arr = [1 , 2];
6060
var obj = {"foo": "bar" ,"baz": "qur"};
6161
foo(a ,b);
6262
new Foo(a ,b);
63-
function foo(a ,b){}
63+
function baz(a ,b){}
6464
a ,b
6565
```
6666

@@ -80,7 +80,7 @@ var arr = [1,, 3]
8080
var obj = {"foo": "bar", "baz": "qur"};
8181
foo(a, b);
8282
new Foo(a, b);
83-
function foo(a, b){}
83+
function qur(a, b){}
8484
a, b
8585
```
8686

@@ -131,7 +131,7 @@ var foo = 1, bar = 2;
131131
var arr = [1 , 2];
132132
var obj = {"foo": "bar", "baz": "qur"};
133133
new Foo(a,b);
134-
function foo(a,b){}
134+
function baz(a,b){}
135135
a, b
136136
```
137137

@@ -151,7 +151,7 @@ var arr = [1 ,,3]
151151
var obj = {"foo": "bar" ,"baz": "qur"};
152152
foo(a ,b);
153153
new Foo(a ,b);
154-
function foo(a ,b){}
154+
function qur(a ,b){}
155155
a ,b
156156
```
157157

docs/src/rules/comma-style.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var foo = 1
6969
var foo = ["apples"
7070
, "oranges"];
7171

72-
function bar() {
72+
function baz() {
7373
return {
7474
"a": 1
7575
,"b:": 2
@@ -94,7 +94,7 @@ var foo = 1,
9494
var foo = ["apples",
9595
"oranges"];
9696

97-
function bar() {
97+
function baz() {
9898
return {
9999
"a": 1,
100100
"b:": 2
@@ -119,7 +119,7 @@ var foo = 1,
119119
var foo = ["apples",
120120
"oranges"];
121121

122-
function bar() {
122+
function baz() {
123123
return {
124124
"a": 1,
125125
"b:": 2
@@ -144,7 +144,7 @@ var foo = 1
144144
var foo = ["apples"
145145
,"oranges"];
146146

147-
function bar() {
147+
function baz() {
148148
return {
149149
"a": 1
150150
,"b:": 2

docs/src/rules/consistent-return.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function doSomething(condition) {
4848
}
4949
}
5050

51-
function doSomething(condition) {
51+
function doSomethingElse(condition) {
5252
if (condition) {
5353
return true;
5454
}

docs/src/rules/default-param-last.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Examples of **incorrect** code for this rule:
2828

2929
function f(a = 0, b) {}
3030

31-
function f(a, b = 0, c) {}
31+
function g(a, b = 0, c) {}
3232
```
3333

3434
:::

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

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ Examples of **incorrect** code for this rule with the `"always"` option:
4949

5050
function foo(bar, baz) {}
5151

52-
var foo = function(bar, baz) {};
52+
var qux = function(bar, baz) {};
5353

54-
var foo = (bar, baz) => {};
54+
var qux = (bar, baz) => {};
5555

5656
foo(bar, baz);
5757
```
@@ -70,11 +70,11 @@ function foo(
7070
baz
7171
) {}
7272

73-
var foo = function(
73+
var qux = function(
7474
bar, baz
7575
) {};
7676

77-
var foo = (
77+
var qux = (
7878
bar,
7979
baz
8080
) => {};
@@ -99,11 +99,11 @@ function foo(
9999
baz
100100
) {}
101101

102-
var foo = function(
102+
var qux = function(
103103
bar, baz
104104
) {};
105105

106-
var foo = (
106+
var qux = (
107107
bar,
108108
baz
109109
) => {};
@@ -125,12 +125,12 @@ Examples of **correct** code for this rule with the `"never"` option:
125125

126126
function foo(bar, baz) {}
127127

128-
function foo(bar,
128+
function qux(bar,
129129
baz) {}
130130

131-
var foo = function(bar, baz) {};
131+
var foobar = function(bar, baz) {};
132132

133-
var foo = (bar, baz) => {};
133+
var foobar = (bar, baz) => {};
134134

135135
foo(bar, baz);
136136

@@ -151,11 +151,11 @@ function foo(bar,
151151
baz
152152
) {}
153153

154-
var foo = function(
154+
var qux = function(
155155
bar, baz
156156
) {};
157157

158-
var foo = (
158+
var qux = (
159159
bar,
160160
baz) => {};
161161

@@ -180,12 +180,12 @@ Examples of **correct** code for this rule with the default `"multiline"` option
180180

181181
function foo(bar, baz) {}
182182

183-
var foo = function(
183+
var foobar = function(
184184
bar,
185185
baz
186186
) {};
187187

188-
var foo = (bar, baz) => {};
188+
var foobar = (bar, baz) => {};
189189

190190
foo(bar, baz, qux);
191191

@@ -213,11 +213,11 @@ function foo(bar,
213213
baz
214214
) {}
215215

216-
var foo = function(bar,
216+
var qux = function(bar,
217217
baz
218218
) {};
219219

220-
var foo = (
220+
var qux = (
221221
bar,
222222
baz) => {};
223223

@@ -243,9 +243,9 @@ Examples of **correct** code for this rule with the `"consistent"` option:
243243
function foo(bar,
244244
baz) {}
245245

246-
var foo = function(bar, baz) {};
246+
var qux = function(bar, baz) {};
247247

248-
var foo = (
248+
var qux = (
249249
bar,
250250
baz
251251
) => {};
@@ -274,11 +274,11 @@ function foo(bar,
274274
baz
275275
) {}
276276

277-
var foo = function(bar,
277+
var foobar = function(bar,
278278
baz
279279
) {};
280280

281-
var foo = (
281+
var foobar = (
282282
bar,
283283
baz) => {};
284284

@@ -306,9 +306,9 @@ function foo(
306306
baz
307307
) {}
308308

309-
var foo = function(bar, baz) {};
309+
var qux = function(bar, baz) {};
310310

311-
var foo = (
311+
var qux = (
312312
bar
313313
) => {};
314314

@@ -333,13 +333,13 @@ function foo(
333333
baz
334334
) {}
335335

336-
function foo(bar, baz, qux) {}
336+
function foobar(bar, baz, qux) {}
337337

338-
var foo = function(
338+
var barbaz = function(
339339
bar, baz
340340
) {};
341341

342-
var foo = (bar,
342+
var barbaz = (bar,
343343
baz) => {};
344344

345345
foo(bar,
@@ -357,13 +357,13 @@ Examples of **correct** code for this rule with the `{ "minItems": 3 }` option:
357357

358358
function foo(bar, baz) {}
359359

360-
var foo = function(
360+
var foobar = function(
361361
bar,
362362
baz,
363363
qux
364364
) {};
365365

366-
var foo = (
366+
var foobar = (
367367
bar, baz, qux
368368
) => {};
369369

docs/src/rules/global-require.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ This rule requires all calls to `require()` to be at the top level of the module
3232

3333
Examples of **incorrect** code for this rule:
3434

35-
::: incorrect
35+
::: incorrect { "sourceType": "script" }
3636

3737
```js
3838
/*eslint global-require: "error"*/
@@ -76,7 +76,7 @@ try {
7676

7777
Examples of **correct** code for this rule:
7878

79-
::: correct
79+
::: correct { "sourceType": "script" }
8080

8181
```js
8282
/*eslint global-require: "error"*/

docs/src/rules/id-length.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ try {
160160
}
161161
var myObj = { apple: 1 };
162162
(value) => { value * value };
163-
function foobar(value = 0) { }
163+
function foobaz(value = 0) { }
164164
class MyClass { }
165165
class Foobar { method() {} }
166-
function foobar(...args) { }
166+
function barbaz(...args) { }
167167
var { prop } = {};
168168
var [longName] = foo;
169169
var { a: [prop] } = {};

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ This is the default option.
6060

6161
Examples of **incorrect** code for this rule with the `"always"` option:
6262

63-
::: incorrect
63+
::: incorrect { "sourceType": "script" }
6464

6565
```js
6666
/* eslint lines-around-directive: ["error", "always"] */
@@ -92,7 +92,7 @@ function foo() {
9292

9393
Examples of **correct** code for this rule with the `"always"` option:
9494

95-
::: correct
95+
::: correct { "sourceType": "script" }
9696

9797
```js
9898
/* eslint lines-around-directive: ["error", "always"] */
@@ -132,7 +132,7 @@ function foo() {
132132

133133
Examples of **incorrect** code for this rule with the `"never"` option:
134134

135-
::: incorrect
135+
::: incorrect { "sourceType": "script" }
136136

137137
```js
138138
/* eslint lines-around-directive: ["error", "never"] */
@@ -171,7 +171,7 @@ function foo() {
171171

172172
Examples of **correct** code for this rule with the `"never"` option:
173173

174-
::: correct
174+
::: correct { "sourceType": "script" }
175175

176176
```js
177177
/* eslint lines-around-directive: ["error", "never"] */
@@ -205,7 +205,7 @@ function foo() {
205205

206206
Examples of **incorrect** code for this rule with the `{ "before": "never", "after": "always" }` option:
207207

208-
::: incorrect
208+
::: incorrect { "sourceType": "script" }
209209

210210
```js
211211
/* eslint lines-around-directive: ["error", { "before": "never", "after": "always" }] */
@@ -240,7 +240,7 @@ function foo() {
240240

241241
Examples of **correct** code for this rule with the `{ "before": "never", "after": "always" }` option:
242242

243-
::: correct
243+
::: correct { "sourceType": "script" }
244244

245245
```js
246246
/* eslint lines-around-directive: ["error", { "before": "never", "after": "always" }] */
@@ -276,7 +276,7 @@ function foo() {
276276

277277
Examples of **incorrect** code for this rule with the `{ "before": "always", "after": "never" }` option:
278278

279-
::: incorrect
279+
::: incorrect { "sourceType": "script" }
280280

281281
```js
282282
/* eslint lines-around-directive: ["error", { "before": "always", "after": "never" }] */
@@ -312,7 +312,7 @@ function foo() {
312312

313313
Examples of **correct** code for this rule with the `{ "before": "always", "after": "never" }` option:
314314

315-
::: correct
315+
::: correct { "sourceType": "script" }
316316

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

0 commit comments

Comments
 (0)