Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: default to sourceType: "module" in rule examples #17615

Merged
merged 5 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/.eleventy.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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