Skip to content

Commit

Permalink
docs: Add correct/incorrect tags to prefer-arrow-callback (#17589)
Browse files Browse the repository at this point in the history
Add correct/incorrect tags
  • Loading branch information
fasttime committed Sep 19, 2023
1 parent aa1b657 commit 48a44a7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/src/rules/prefer-arrow-callback.md
Expand Up @@ -23,6 +23,8 @@ This rule locates function expressions used as callbacks or function arguments.

The following examples **will** be flagged:

::: incorrect

```js
/* eslint prefer-arrow-callback: "error" */

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

:::

Instances where an arrow function would not produce identical results will be ignored.

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

::: correct

```js
/* eslint prefer-arrow-callback: "error" */
/* eslint-env es6 */
Expand All @@ -57,6 +63,8 @@ foo(function() { return this.a; }); // OK
foo(function bar(n) { return n && n + bar(n - 1); }); // OK
```

:::

## Options

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

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

::: correct

```js
/* eslint prefer-arrow-callback: [ "error", { "allowNamedFunctions": true } ] */

foo(function bar() {});
```

:::

### allowUnboundThis

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.
Expand All @@ -85,6 +97,8 @@ When set to `false` this option prohibits the use of function expressions as cal

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

::: incorrect

```js
/* eslint prefer-arrow-callback: [ "error", { "allowUnboundThis": false } ] */
/* eslint-env es6 */
Expand All @@ -96,6 +110,8 @@ foo(function() { (() => this); });
someArray.map(function(item) { return this.doSomething(item); }, someObject);
```

:::

## When Not To Use It

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

0 comments on commit 48a44a7

Please sign in to comment.