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: fix examples for several rules #17645

Merged
merged 1 commit into from Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions docs/src/rules/arrow-body-style.md
Expand Up @@ -32,6 +32,7 @@ Examples of **incorrect** code for this rule with the `"always"` option:
```js
/*eslint arrow-body-style: ["error", "always"]*/
/*eslint-env es6*/

let foo = () => 0;
```

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

```js
/*eslint arrow-body-style: ["error", "always"]*/
/*eslint-env es6*/

let foo = () => {
return 0;
};
Expand Down
12 changes: 8 additions & 4 deletions docs/src/rules/function-paren-newline.md
Expand Up @@ -339,11 +339,15 @@ var barbaz = function(
bar, baz
) {};

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

foo(bar,
baz);
foo(
bar,
baz
);
Comment on lines -342 to +350
Copy link
Member Author

Choose a reason for hiding this comment

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

These examples in "incorrect" were "correct".

```

:::
Expand Down
2 changes: 1 addition & 1 deletion docs/src/rules/id-match.md
Expand Up @@ -143,7 +143,7 @@ Examples of **correct** code for this rule with the `"^[a-z]+([A-Z][a-z]+)*$", {
```js
/*eslint id-match: [2, "^[a-z]+([A-Z][a-z]+)*$", { "onlyDeclarations": true }]*/

do_something(__dirname);
foo = __dirname;
Copy link
Member Author

Choose a reason for hiding this comment

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

This was "correct" regardless of the option, so I replaced it with an example that would be "incorrect" with "onlyDeclarations": false

```

:::
Expand Down
4 changes: 2 additions & 2 deletions docs/src/rules/indent.md
Expand Up @@ -192,7 +192,7 @@ Examples of **correct** code for this rule with the `4, { "ignoredNodes": ["Call
foo();
bar();

})
})();
Copy link
Member Author

Choose a reason for hiding this comment

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

The selector targets IIFEs. This wasn't an IIFE, so it was "incorrect".

```

:::
Expand Down Expand Up @@ -403,7 +403,7 @@ function foo(x) {
})();

if (y) {
console.log('foo');
console.log('foo');
}
```

Expand Down
166 changes: 112 additions & 54 deletions docs/src/rules/lines-around-directive.md
Expand Up @@ -65,14 +65,8 @@ Examples of **incorrect** code for this rule with the `"always"` option:
```js
/* eslint lines-around-directive: ["error", "always"] */

/* Top of file */
"use strict";
var foo;

/* Top of file */
// comment
"use strict";
"use asm";
var foo;

function foo() {
Expand All @@ -90,23 +84,29 @@ function foo() {

:::

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

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

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

/* Top of file */
// comment
"use strict";

"use asm";
var foo;
```

:::

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

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

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

/* Top of file */
// comment

"use strict";
"use asm";

var foo;

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

:::

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

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

// comment

"use strict";
"use asm";

var foo;
```

:::

### never

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

/* Top of file */

"use strict";

var foo;

/* Top of file */
// comment

"use strict";
"use asm";

var foo;

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

:::

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

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

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

/* Top of file */
// comment

"use strict";
"use asm";

var foo;
```

:::

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

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

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

/* Top of file */
// comment
"use strict";
"use asm";
var foo;

function foo() {
Expand All @@ -201,6 +217,19 @@ function foo() {

:::

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

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

// comment
"use strict";
"use asm";
var foo;
```

:::

### before & after

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

/* Top of file */

"use strict";
var foo;

/* Top of file */
// comment

"use strict";
"use asm";
var foo;

function foo() {
Expand All @@ -238,22 +260,29 @@ function foo() {

:::

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

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

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

/* Top of file */
"use strict";
// comment

"use strict";
"use asm";
var foo;
```

:::

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

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

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

/* Top of file */
// comment
"use strict";
"use asm";

var foo;

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

:::

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

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

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

/* Top of file */
// comment
"use strict";
"use asm";

var foo;
```

:::

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

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

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

/* Top of file */
// comment
"use strict";
"use asm";

var foo;

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

:::

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

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

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

/* Top of file */
// comment
"use strict";
"use asm";

var foo;
```

:::

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

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

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

/* Top of file */
// comment

"use strict";
"use asm";
var foo;

function foo() {
Expand All @@ -344,6 +388,20 @@ function foo() {

:::

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

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

// comment

"use strict";
"use asm";
var foo;
```

:::

## When Not To Use It

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.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/rules/max-statements-per-line.md
Expand Up @@ -76,7 +76,7 @@ if (condition) { bar = 1; } else { baz = 2; }
for (var i = 0; i < length; ++i) { bar = 1; baz = 2; }
switch (discriminant) { case 'test': break; default: break; }
function foo() { bar = 1; baz = 2; }
var qux = function qux() { bar = 1; };
var qux = function qux() { bar = 1; baz = 2; };
Copy link
Member Author

Choose a reason for hiding this comment

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

Function expression doesn't count as a statement, so this was "correct".

(function foo() { bar = 1; baz = 2; })();
```

Expand Down