From d86a5bbb1987d858d4963f647b0af5c1fd924b4f Mon Sep 17 00:00:00 2001 From: Milos Djermanovic Date: Fri, 17 Jan 2020 16:59:41 +0100 Subject: [PATCH] Breaking: Check flatMap in array-callback-return (fixes #12235) (#12765) --- docs/rules/array-callback-return.md | 1 + lib/rules/array-callback-return.js | 2 +- tests/lib/rules/array-callback-return.js | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/rules/array-callback-return.md b/docs/rules/array-callback-return.md index 34ffeffcebd..44dccdefff8 100644 --- a/docs/rules/array-callback-return.md +++ b/docs/rules/array-callback-return.md @@ -21,6 +21,7 @@ This rule finds callback functions of the following methods, then checks usage o * [`Array.prototype.filter`](https://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.filter) * [`Array.prototype.find`](https://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.find) * [`Array.prototype.findIndex`](https://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.findindex) +* [`Array.prototype.flatMap`](https://www.ecma-international.org/ecma-262/10.0/#sec-array.prototype.flatmap) * [`Array.prototype.map`](https://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.map) * [`Array.prototype.reduce`](https://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.reduce) * [`Array.prototype.reduceRight`](https://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.reduceright) diff --git a/lib/rules/array-callback-return.js b/lib/rules/array-callback-return.js index d632a3f30c2..6e425dcdcb8 100644 --- a/lib/rules/array-callback-return.js +++ b/lib/rules/array-callback-return.js @@ -18,7 +18,7 @@ const astUtils = require("./utils/ast-utils"); //------------------------------------------------------------------------------ const TARGET_NODE_TYPE = /^(?:Arrow)?FunctionExpression$/u; -const TARGET_METHODS = /^(?:every|filter|find(?:Index)?|map|reduce(?:Right)?|some|sort)$/u; +const TARGET_METHODS = /^(?:every|filter|find(?:Index)?|flatMap|map|reduce(?:Right)?|some|sort)$/u; /** * Checks a given code path segment is reachable. diff --git a/tests/lib/rules/array-callback-return.js b/tests/lib/rules/array-callback-return.js index de39efcf6b9..2816d796246 100644 --- a/tests/lib/rules/array-callback-return.js +++ b/tests/lib/rules/array-callback-return.js @@ -36,6 +36,7 @@ ruleTester.run("array-callback-return", rule, { "foo.filter(function() { return true; })", "foo.find(function() { return true; })", "foo.findIndex(function() { return true; })", + "foo.flatMap(function() { return true; })", "foo.map(function() { return true; })", "foo.reduce(function() { return true; })", "foo.reduceRight(function() { return true; })", @@ -47,6 +48,7 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.filter(function() { return; })", options: allowImplicitOptions }, { code: "foo.find(function() { return; })", options: allowImplicitOptions }, { code: "foo.findIndex(function() { return; })", options: allowImplicitOptions }, + { code: "foo.flatMap(function() { return; })", options: allowImplicitOptions }, { code: "foo.map(function() { return; })", options: allowImplicitOptions }, { code: "foo.reduce(function() { return; })", options: allowImplicitOptions }, { code: "foo.reduceRight(function() { return; })", options: allowImplicitOptions }, @@ -94,6 +96,8 @@ ruleTester.run("array-callback-return", rule, { { code: "foo.find(function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'" } }] }, { code: "foo.findIndex(function() {})", errors: [{ messageId: "expectedInside", data: { name: "function" } }] }, { code: "foo.findIndex(function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'" } }] }, + { code: "foo.flatMap(function() {})", errors: [{ messageId: "expectedInside", data: { name: "function" } }] }, + { code: "foo.flatMap(function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'" } }] }, { code: "foo.map(function() {})", errors: [{ messageId: "expectedInside", data: { name: "function" } }] }, { code: "foo.map(function foo() {})", errors: [{ messageId: "expectedInside", data: { name: "function 'foo'" } }] }, { code: "foo.reduce(function() {})", errors: [{ messageId: "expectedInside", data: { name: "function" } }] },