Skip to content

Commit 48a44a7

Browse files
authored
docs: Add correct/incorrect tags to prefer-arrow-callback (#17589)
Add correct/incorrect tags
1 parent aa1b657 commit 48a44a7

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

docs/src/rules/prefer-arrow-callback.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ This rule locates function expressions used as callbacks or function arguments.
2323

2424
The following examples **will** be flagged:
2525

26+
::: incorrect
27+
2628
```js
2729
/* eslint prefer-arrow-callback: "error" */
2830

@@ -33,10 +35,14 @@ foo(function() { return this.a; }.bind(this)); // ERROR
3335
// prefer: foo(() => this.a)
3436
```
3537

38+
:::
39+
3640
Instances where an arrow function would not produce identical results will be ignored.
3741

3842
The following examples **will not** be flagged:
3943

44+
::: correct
45+
4046
```js
4147
/* eslint prefer-arrow-callback: "error" */
4248
/* eslint-env es6 */
@@ -57,6 +63,8 @@ foo(function() { return this.a; }); // OK
5763
foo(function bar(n) { return n && n + bar(n - 1); }); // OK
5864
```
5965

66+
:::
67+
6068
## Options
6169

6270
Access further control over this rule's behavior via an options object.
@@ -71,12 +79,16 @@ Changing this value to `true` will reverse this option's behavior by allowing us
7179

7280
`{ "allowNamedFunctions": true }` **will not** flag the following example:
7381

82+
::: correct
83+
7484
```js
7585
/* eslint prefer-arrow-callback: [ "error", { "allowNamedFunctions": true } ] */
7686

7787
foo(function bar() {});
7888
```
7989

90+
:::
91+
8092
### allowUnboundThis
8193

8294
By default `{ "allowUnboundThis": true }`, this `boolean` option allows function expressions containing `this` to be used as callbacks, as long as the function in question has not been explicitly bound.
@@ -85,6 +97,8 @@ When set to `false` this option prohibits the use of function expressions as cal
8597

8698
`{ "allowUnboundThis": false }` **will** flag the following examples:
8799

100+
::: incorrect
101+
88102
```js
89103
/* eslint prefer-arrow-callback: [ "error", { "allowUnboundThis": false } ] */
90104
/* eslint-env es6 */
@@ -96,6 +110,8 @@ foo(function() { (() => this); });
96110
someArray.map(function(item) { return this.doSomething(item); }, someObject);
97111
```
98112

113+
:::
114+
99115
## When Not To Use It
100116

101117
* In environments that have not yet adopted ES6 language features (ES3/5).

0 commit comments

Comments
 (0)