From 48a44a73ac456739bdee348bbaf1840d2b1e4830 Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Tue, 19 Sep 2023 09:16:44 +0200 Subject: [PATCH] docs: Add correct/incorrect tags to `prefer-arrow-callback` (#17589) Add correct/incorrect tags --- docs/src/rules/prefer-arrow-callback.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/src/rules/prefer-arrow-callback.md b/docs/src/rules/prefer-arrow-callback.md index 0d724938447..d3e9000561c 100644 --- a/docs/src/rules/prefer-arrow-callback.md +++ b/docs/src/rules/prefer-arrow-callback.md @@ -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" */ @@ -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 */ @@ -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. @@ -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. @@ -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 */ @@ -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).