Skip to content

Commit

Permalink
docs: default to sourceType: "module" in rule examples (#17615)
Browse files Browse the repository at this point in the history
* Default to `"sourceType": "module"` in rule examples

* Fix `sourceType` in obvious cases

* Fix `sourceType` in less obvious cases

* Fix name conflicts

* Apply suggestions
  • Loading branch information
fasttime committed Oct 5, 2023
1 parent dd79abc commit ee5be81
Show file tree
Hide file tree
Showing 53 changed files with 296 additions and 301 deletions.
5 changes: 3 additions & 2 deletions docs/.eleventy.js
Expand Up @@ -205,11 +205,12 @@ module.exports = function(eleventyConfig) {
}

// See https://github.com/eslint/eslint.org/blob/ac38ab41f99b89a8798d374f74e2cce01171be8b/src/playground/App.js#L44
const parserOptions = tokens[index].info?.split("correct ")[1]?.trim();
const parserOptionsJSON = tokens[index].info?.split("correct ")[1]?.trim();
const parserOptions = { sourceType: "module", ...(parserOptionsJSON && JSON.parse(parserOptionsJSON)) };
const { content } = tokens[index + 1];
const state = encodeToBase64(
JSON.stringify({
...(parserOptions && { options: { parserOptions: JSON.parse(parserOptions) } }),
options: { parserOptions },
text: content
})
);
Expand Down
2 changes: 1 addition & 1 deletion docs/src/rules/camelcase.md
Expand Up @@ -328,7 +328,7 @@ function UNSAFE_componentWillMount() {
// ...
}

function UNSAFE_componentWillMount() {
function UNSAFE_componentWillReceiveProps() {
// ...
}
```
Expand Down
8 changes: 4 additions & 4 deletions docs/src/rules/comma-spacing.md
Expand Up @@ -60,7 +60,7 @@ var arr = [1 , 2];
var obj = {"foo": "bar" ,"baz": "qur"};
foo(a ,b);
new Foo(a ,b);
function foo(a ,b){}
function baz(a ,b){}
a ,b
```

Expand All @@ -80,7 +80,7 @@ var arr = [1,, 3]
var obj = {"foo": "bar", "baz": "qur"};
foo(a, b);
new Foo(a, b);
function foo(a, b){}
function qur(a, b){}
a, b
```

Expand Down Expand Up @@ -131,7 +131,7 @@ var foo = 1, bar = 2;
var arr = [1 , 2];
var obj = {"foo": "bar", "baz": "qur"};
new Foo(a,b);
function foo(a,b){}
function baz(a,b){}
a, b
```

Expand All @@ -151,7 +151,7 @@ var arr = [1 ,,3]
var obj = {"foo": "bar" ,"baz": "qur"};
foo(a ,b);
new Foo(a ,b);
function foo(a ,b){}
function qur(a ,b){}
a ,b
```

Expand Down
8 changes: 4 additions & 4 deletions docs/src/rules/comma-style.md
Expand Up @@ -69,7 +69,7 @@ var foo = 1
var foo = ["apples"
, "oranges"];

function bar() {
function baz() {
return {
"a": 1
,"b:": 2
Expand All @@ -94,7 +94,7 @@ var foo = 1,
var foo = ["apples",
"oranges"];

function bar() {
function baz() {
return {
"a": 1,
"b:": 2
Expand All @@ -119,7 +119,7 @@ var foo = 1,
var foo = ["apples",
"oranges"];

function bar() {
function baz() {
return {
"a": 1,
"b:": 2
Expand All @@ -144,7 +144,7 @@ var foo = 1
var foo = ["apples"
,"oranges"];

function bar() {
function baz() {
return {
"a": 1
,"b:": 2
Expand Down
2 changes: 1 addition & 1 deletion docs/src/rules/consistent-return.md
Expand Up @@ -48,7 +48,7 @@ function doSomething(condition) {
}
}

function doSomething(condition) {
function doSomethingElse(condition) {
if (condition) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/rules/default-param-last.md
Expand Up @@ -28,7 +28,7 @@ Examples of **incorrect** code for this rule:

function f(a = 0, b) {}

function f(a, b = 0, c) {}
function g(a, b = 0, c) {}
```

:::
Expand Down
52 changes: 26 additions & 26 deletions docs/src/rules/function-paren-newline.md
Expand Up @@ -49,9 +49,9 @@ Examples of **incorrect** code for this rule with the `"always"` option:

function foo(bar, baz) {}

var foo = function(bar, baz) {};
var qux = function(bar, baz) {};

var foo = (bar, baz) => {};
var qux = (bar, baz) => {};

foo(bar, baz);
```
Expand All @@ -70,11 +70,11 @@ function foo(
baz
) {}

var foo = function(
var qux = function(
bar, baz
) {};

var foo = (
var qux = (
bar,
baz
) => {};
Expand All @@ -99,11 +99,11 @@ function foo(
baz
) {}

var foo = function(
var qux = function(
bar, baz
) {};

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

function foo(bar, baz) {}

function foo(bar,
function qux(bar,
baz) {}

var foo = function(bar, baz) {};
var foobar = function(bar, baz) {};

var foo = (bar, baz) => {};
var foobar = (bar, baz) => {};

foo(bar, baz);

Expand All @@ -151,11 +151,11 @@ function foo(bar,
baz
) {}

var foo = function(
var qux = function(
bar, baz
) {};

var foo = (
var qux = (
bar,
baz) => {};

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

function foo(bar, baz) {}

var foo = function(
var foobar = function(
bar,
baz
) {};

var foo = (bar, baz) => {};
var foobar = (bar, baz) => {};

foo(bar, baz, qux);

Expand Down Expand Up @@ -213,11 +213,11 @@ function foo(bar,
baz
) {}

var foo = function(bar,
var qux = function(bar,
baz
) {};

var foo = (
var qux = (
bar,
baz) => {};

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

var foo = function(bar, baz) {};
var qux = function(bar, baz) {};

var foo = (
var qux = (
bar,
baz
) => {};
Expand Down Expand Up @@ -274,11 +274,11 @@ function foo(bar,
baz
) {}

var foo = function(bar,
var foobar = function(bar,
baz
) {};

var foo = (
var foobar = (
bar,
baz) => {};

Expand Down Expand Up @@ -306,9 +306,9 @@ function foo(
baz
) {}

var foo = function(bar, baz) {};
var qux = function(bar, baz) {};

var foo = (
var qux = (
bar
) => {};

Expand All @@ -333,13 +333,13 @@ function foo(
baz
) {}

function foo(bar, baz, qux) {}
function foobar(bar, baz, qux) {}

var foo = function(
var barbaz = function(
bar, baz
) {};

var foo = (bar,
var barbaz = (bar,
baz) => {};

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

function foo(bar, baz) {}

var foo = function(
var foobar = function(
bar,
baz,
qux
) {};

var foo = (
var foobar = (
bar, baz, qux
) => {};

Expand Down
4 changes: 2 additions & 2 deletions docs/src/rules/global-require.md
Expand Up @@ -32,7 +32,7 @@ This rule requires all calls to `require()` to be at the top level of the module

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

::: incorrect
::: incorrect { "sourceType": "script" }

```js
/*eslint global-require: "error"*/
Expand Down Expand Up @@ -76,7 +76,7 @@ try {

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

::: correct
::: correct { "sourceType": "script" }

```js
/*eslint global-require: "error"*/
Expand Down
4 changes: 2 additions & 2 deletions docs/src/rules/id-length.md
Expand Up @@ -160,10 +160,10 @@ try {
}
var myObj = { apple: 1 };
(value) => { value * value };
function foobar(value = 0) { }
function foobaz(value = 0) { }
class MyClass { }
class Foobar { method() {} }
function foobar(...args) { }
function barbaz(...args) { }
var { prop } = {};
var [longName] = foo;
var { a: [prop] } = {};
Expand Down
16 changes: 8 additions & 8 deletions docs/src/rules/lines-around-directive.md
Expand Up @@ -60,7 +60,7 @@ This is the default option.

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

::: incorrect
::: incorrect { "sourceType": "script" }

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

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

::: correct
::: correct { "sourceType": "script" }

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

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

::: incorrect
::: incorrect { "sourceType": "script" }

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

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

::: correct
::: correct { "sourceType": "script" }

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

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

::: incorrect
::: incorrect { "sourceType": "script" }

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

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

::: correct
::: correct { "sourceType": "script" }

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

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

::: incorrect
::: incorrect { "sourceType": "script" }

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

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

::: correct
::: correct { "sourceType": "script" }

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

0 comments on commit ee5be81

Please sign in to comment.