Skip to content

Commit

Permalink
docs: fix examples for several rules (#17645)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic committed Oct 13, 2023
1 parent 179929b commit a58aa20
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 69 deletions.
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
);
```

:::
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;
```

:::
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();

})
})();
```

:::
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; };
(function foo() { bar = 1; baz = 2; })();
```

Expand Down

0 comments on commit a58aa20

Please sign in to comment.