Skip to content

Commit a3b2e90

Browse files
authored
Update style for rule fail/pass examples (2/5) (#2754)
1 parent cd7b0da commit a3b2e90

24 files changed

+344
-281
lines changed

docs/rules/no-for-loop.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,29 @@ Off-by-one errors are one of the most common bugs in software. [Swift actually r
1313

1414
This rule is fixable unless index or element variables were used outside of the loop.
1515

16-
## Fail
16+
## Examples
1717

1818
```js
19+
//
1920
for (let index = 0; index < array.length; index++) {
2021
const element = array[index];
2122
console.log(index, element);
2223
}
23-
```
24-
25-
## Pass
2624

27-
```js
25+
//
2826
for (const [index, element] of array.entries()) {
2927
console.log(index, element);
3028
}
29+
```
30+
31+
```js
32+
//
33+
for (let index = 0; index < array.length; index++) {
34+
const element = array[index];
35+
console.log(element);
36+
}
3137

38+
//
3239
for (const element of array) {
3340
console.log(element);
3441
}

docs/rules/no-hex-escape.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@
99

1010
Enforces a convention of using [Unicode escapes](https://mathiasbynens.be/notes/javascript-escapes#unicode) instead of [hexadecimal escapes](https://mathiasbynens.be/notes/javascript-escapes#hexadecimal) for consistency and clarity.
1111

12-
## Fail
12+
## Examples
1313

1414
```js
15+
//
1516
const foo = '\x1B';
16-
const foo = `\x1B${bar}`;
17-
```
1817

19-
## Pass
18+
//
19+
const foo = '\u001B';
20+
```
2021

2122
```js
22-
const foo = '\u001B';
23+
//
24+
const foo = `\x1B${bar}`;
25+
26+
//
2327
const foo = `\u001B${bar}`;
2428
```

docs/rules/no-instanceof-builtins.md

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,77 @@ Therefore, it is recommended to use a safer method, like `Object.prototype.toStr
1414
## Examples
1515

1616
```js
17-
foo instanceof String; //
18-
typeof foo === 'string'; //
17+
//
18+
foo instanceof String;
19+
20+
//
21+
typeof foo === 'string';
1922
```
2023

2124
```js
22-
foo instanceof Number; //
23-
typeof foo === 'number'; //
25+
//
26+
foo instanceof Number;
27+
28+
//
29+
typeof foo === 'number';
2430
```
2531

2632
```js
27-
foo instanceof Boolean; //
28-
typeof foo === 'boolean'; //
33+
//
34+
foo instanceof Boolean;
35+
36+
//
37+
typeof foo === 'boolean';
2938
```
3039

3140
```js
32-
foo instanceof BigInt; //
33-
typeof foo === 'bigint'; //
41+
//
42+
foo instanceof BigInt;
43+
44+
//
45+
typeof foo === 'bigint';
3446
```
3547

3648
```js
37-
foo instanceof Symbol; //
38-
typeof foo === 'symbol'; //
49+
//
50+
foo instanceof Symbol;
51+
52+
//
53+
typeof foo === 'symbol';
3954
```
4055

4156
```js
42-
foo instanceof Array; //
43-
Array.isArray(foo); //
57+
//
58+
foo instanceof Array;
59+
60+
//
61+
Array.isArray(foo);
4462
```
4563

4664
```js
47-
foo instanceof Function; //
48-
typeof foo === 'function'; //
65+
//
66+
foo instanceof Function;
67+
68+
//
69+
typeof foo === 'function';
4970
```
5071

5172
```js
52-
foo instanceof Object; //
53-
Object.prototype.toString.call(foo) === '[object Object]'; //
73+
//
74+
foo instanceof Object;
75+
76+
//
77+
Object.prototype.toString.call(foo) === '[object Object]';
5478
```
5579

5680
```js
5781
import is from '@sindresorhus/is';
5882

59-
foo instanceof Map; //
60-
is(foo) === 'Map'; //
83+
//
84+
foo instanceof Map;
85+
86+
//
87+
is(foo) === 'Map';
6188
```
6289

6390
## Options

docs/rules/no-invalid-fetch-options.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,40 @@
77

88
[`fetch()`](https://developer.mozilla.org/en-US/docs/Web/API/fetch) throws a `TypeError` when the method is `GET` or `HEAD` and a body is provided.
99

10-
## Fail
10+
## Examples
1111

1212
```js
13+
//
1314
const response = await fetch('/', {body: 'foo=bar'});
1415
```
1516

1617
```js
18+
//
1719
const request = new Request('/', {body: 'foo=bar'});
1820
```
1921

2022
```js
21-
const response = await fetch('/', {method: 'GET', body: 'foo=bar'});
22-
```
23-
24-
```js
25-
const request = new Request('/', {method: 'GET', body: 'foo=bar'});
26-
```
27-
28-
## Pass
29-
30-
```js
23+
//
3124
const response = await fetch('/', {method: 'HEAD'});
3225
```
3326

3427
```js
28+
//
3529
const request = new Request('/', {method: 'HEAD'});
3630
```
3731

3832
```js
33+
//
34+
const response = await fetch('/', {method: 'GET', body: 'foo=bar'});
35+
36+
//
3937
const response = await fetch('/', {method: 'POST', body: 'foo=bar'});
4038
```
4139

4240
```js
41+
//
42+
const request = new Request('/', {method: 'GET', body: 'foo=bar'});
43+
44+
//
4345
const request = new Request('/', {method: 'POST', body: 'foo=bar'});
4446
```

docs/rules/no-invalid-remove-event-listener.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,42 @@
77

88
The [`removeEventListener`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener) function must be called with a reference to the same function that was passed to [`addEventListener`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener). Calling `removeEventListener` with an inline function or the result of an inline `.bind()` call is indicative of an error, and won't actually remove the listener.
99

10-
## Fail
10+
## Examples
1111

1212
```js
13-
window.removeEventListener('click', fn.bind(window));
13+
//
14+
window.removeEventListener('click', listener.bind(window));
15+
16+
//
17+
window.removeEventListener('click', listener);
1418
```
1519

1620
```js
21+
//
22+
window.removeEventListener('click', getListener());
23+
```
24+
25+
```js
26+
//
1727
window.removeEventListener('click', () => {});
1828
```
1929

2030
```js
31+
//
2132
window.removeEventListener('click', function () {});
2233
```
2334

2435
```js
36+
//
2537
class MyElement extends HTMLElement {
2638
handler() {}
2739

2840
disconnectedCallback() {
2941
this.removeEventListener('click', this.handler.bind(this));
3042
}
3143
}
32-
```
3344

34-
## Pass
35-
36-
```js
37-
window.removeEventListener('click', listener);
38-
```
39-
40-
```js
41-
window.removeEventListener('click', getListener());
42-
```
43-
44-
```js
45+
//
4546
class MyElement extends HTMLElement {
4647
constructor() {
4748
super();

docs/rules/no-keyword-prefix.md

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,25 @@
77

88
`new Foo` and `newFoo` look very similar. Use alternatives that do not look like keyword usage.
99

10-
## Fail
10+
## Examples
1111

1212
```js
13+
//
1314
const newFoo = 'foo';
14-
const classFoo = 'foo';
15-
```
1615

17-
## Pass
16+
//
17+
const classFoo = 'foo';
1818

19-
```js
19+
//
2020
const foo = 'foo';
21+
22+
//
2123
const _newFoo = 'foo';
24+
25+
//
2226
const new_foo = 'foo';
27+
28+
//
2329
const fooNew = 'foo';
2430
```
2531

@@ -31,10 +37,11 @@ If you want a custom list of disallowed prefixes you can set them with `disallow
3137

3238
```js
3339
// eslint unicorn/no-keyword-prefix: ["error", {"disallowedPrefixes": ["new", "for"]}]
34-
const classFoo = "a"; // pass
40+
//
41+
const classFoo = "a";
3542

36-
// eslint unicorn/no-keyword-prefix: ["error", {"disallowedPrefixes": ["new", "for"]}]
37-
const forFoo = "a"; // fail
43+
//
44+
const forFoo = "a";
3845
```
3946

4047
The default is `["new", "class"]`.
@@ -45,12 +52,16 @@ If you want to disable this rule for properties, set `checkProperties` to `false
4552

4653
```js
4754
// eslint unicorn/no-keyword-prefix: ["error", {"checkProperties": true}]
48-
foo.newFoo = 2; // fail
55+
//
56+
foo.newFoo = 2;
57+
```
4958

59+
```js
5060
// eslint unicorn/no-keyword-prefix: ["error", {"checkProperties": false}]
61+
//
5162
var foo = {newFoo: 1}; // pass
5263

53-
// eslint unicorn/no-keyword-prefix: ["error", {"checkProperties": false}]
64+
//
5465
foo.newFoo = 2; // pass
5566
```
5667

@@ -60,8 +71,12 @@ The default behavior is to check for camel case usage. If you want to disallow t
6071

6172
```js
6273
// eslint unicorn/no-keyword-prefix: ["error", {"onlyCamelCase": true}]
63-
const new_foo = "foo"; // pass
74+
//
75+
const new_foo = "foo";
76+
```
6477

78+
```js
6579
// eslint unicorn/no-keyword-prefix: ["error", {"onlyCamelCase": false}]
66-
const new_foo = "foo"; // fail
80+
//
81+
const new_foo = "foo";
6782
```

0 commit comments

Comments
 (0)