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 3 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 @@ -319,7 +319,7 @@ function UNSAFE_componentWillMount() {

:::

::: correct
::: correct { "sourceType": "script" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a better fix here would be to change the name of the second function so that it's not a duplicate but also matches the ^UNSAFE_ pattern. It seems very unlikely that the intent was really to redeclare the function. It's much more likely that the intent was to show that the regex can allow multiple different names.


```js
/*eslint camelcase: ["error", {allow: ["^UNSAFE_"]}]*/
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 @@ -50,7 +50,7 @@ This rule has an object option:

Examples of **incorrect** code for this rule with the default `{ "before": false, "after": true }` options:

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

```js
/*eslint comma-spacing: ["error", { "before": false, "after": true }]*/
Expand All @@ -68,7 +68,7 @@ a ,b

Examples of **correct** code for this rule with the default `{ "before": false, "after": true }` options:

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

```js
/*eslint comma-spacing: ["error", { "before": false, "after": true }]*/
Expand Down Expand Up @@ -122,7 +122,7 @@ foo(a, b,)

Examples of **incorrect** code for this rule with the `{ "before": true, "after": false }` options:

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

```js
/*eslint comma-spacing: ["error", { "before": true, "after": false }]*/
Expand All @@ -139,7 +139,7 @@ a, b

Examples of **correct** code for this rule with the `{ "before": true, "after": false }` options:

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

```js
/*eslint comma-spacing: ["error", { "before": true, "after": false }]*/
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 @@ -54,7 +54,7 @@ A way to determine the node types as defined by [ESTree](https://github.com/estr

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

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

```js
/*eslint comma-style: ["error", "last"]*/
Expand All @@ -81,7 +81,7 @@ function bar() {

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

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

```js
/*eslint comma-style: ["error", "last"]*/
Expand All @@ -108,7 +108,7 @@ function bar() {

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

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

```js
/*eslint comma-style: ["error", "first"]*/
Expand All @@ -131,7 +131,7 @@ function bar() {

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

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

```js
/*eslint comma-style: ["error", "first"]*/
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 @@ -35,7 +35,7 @@ This rule requires `return` statements to either always or never specify values.

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

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

```js
/*eslint consistent-return: "error"*/
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 @@ -21,7 +21,7 @@ This rule enforces default parameters to be the last of parameters.

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

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

```js
/* eslint default-param-last: ["error"] */
Expand Down
24 changes: 12 additions & 12 deletions docs/src/rules/function-paren-newline.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Example configurations:

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

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

```js
/* eslint function-paren-newline: ["error", "always"] */
Expand All @@ -60,7 +60,7 @@ foo(bar, baz);

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

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

```js
/* eslint function-paren-newline: ["error", "always"] */
Expand Down Expand Up @@ -89,7 +89,7 @@ foo(

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

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

```js
/* eslint function-paren-newline: ["error", "never"] */
Expand Down Expand Up @@ -118,7 +118,7 @@ foo(

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

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

```js
/* eslint function-paren-newline: ["error", "never"] */
Expand All @@ -142,7 +142,7 @@ foo(bar,

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

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

```js
/* eslint function-paren-newline: ["error", "multiline"] */
Expand Down Expand Up @@ -173,7 +173,7 @@ foo(

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

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

```js
/* eslint function-paren-newline: ["error", "multiline"] */
Expand Down Expand Up @@ -204,7 +204,7 @@ foo(function() {

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

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

```js
/* eslint function-paren-newline: ["error", "consistent"] */
Expand Down Expand Up @@ -235,7 +235,7 @@ foo(

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

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

```js
/* eslint function-paren-newline: ["error", "consistent"] */
Expand Down Expand Up @@ -265,7 +265,7 @@ foo(

Examples of **incorrect** code for this rule with the `"multiline-arguments"` option:

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

```js
/* eslint function-paren-newline: ["error", "multiline-arguments"] */
Expand Down Expand Up @@ -296,7 +296,7 @@ foo(

Examples of **correct** code for this rule with the consistent `"multiline-arguments"` option:

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

```js
/* eslint function-paren-newline: ["error", "multiline-arguments"] */
Expand All @@ -323,7 +323,7 @@ foo(

Examples of **incorrect** code for this rule with the `{ "minItems": 3 }` option:

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

```js
/* eslint function-paren-newline: ["error", { "minItems": 3 }] */
Expand All @@ -350,7 +350,7 @@ foo(bar,

Examples of **correct** code for this rule with the `{ "minItems": 3 }` option:

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

```js
/* eslint function-paren-newline: ["error", { "minItems": 3 }] */
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
2 changes: 1 addition & 1 deletion docs/src/rules/id-length.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ var { prop: [x]} = {};

Examples of **correct** code for this rule with the `{ "min": 4 }` option:

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

```js
/*eslint id-length: ["error", { "min": 4 }]*/
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
8 changes: 4 additions & 4 deletions docs/src/rules/max-statements-per-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The "max" object property is optional (default: 1).

Examples of **incorrect** code for this rule with the default `{ "max": 1 }` option:

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

```js
/*eslint max-statements-per-line: ["error", { "max": 1 }]*/
Expand All @@ -48,7 +48,7 @@ var foo = function foo() { bar = 1; };

Examples of **correct** code for this rule with the default `{ "max": 1 }` option:

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

```js
/*eslint max-statements-per-line: ["error", { "max": 1 }]*/
Expand All @@ -66,7 +66,7 @@ var foo = function foo() { };

Examples of **incorrect** code for this rule with the `{ "max": 2 }` option:

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

```js
/*eslint max-statements-per-line: ["error", { "max": 2 }]*/
Expand All @@ -84,7 +84,7 @@ var foo = function foo() { bar = 1; };

Examples of **correct** code for this rule with the `{ "max": 2 }` option:

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

```js
/*eslint max-statements-per-line: ["error", { "max": 2 }]*/
Expand Down
4 changes: 2 additions & 2 deletions docs/src/rules/newline-before-return.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ This rule requires an empty line before `return` statements to increase code cla

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

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

```js
/*eslint newline-before-return: "error"*/
Expand All @@ -70,7 +70,7 @@ function foo(bar) {

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

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

```js
/*eslint newline-before-return: "error"*/
Expand Down
4 changes: 2 additions & 2 deletions docs/src/rules/no-catch-shadow.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This rule is aimed at preventing unexpected behavior in your program that may ar

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

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

```js
/*eslint no-catch-shadow: "error"*/
Expand Down Expand Up @@ -54,7 +54,7 @@ try {

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

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

```js
/*eslint no-catch-shadow: "error"*/
Expand Down