From abb4871068f792d7fd4912b6becabc386c01ee0e Mon Sep 17 00:00:00 2001 From: Kyle Hensel Date: Sat, 11 Feb 2023 22:07:14 +1300 Subject: [PATCH] [Fix] `no-array-index-key`: consider flatMap --- CHANGELOG.md | 5 +++++ docs/rules/no-array-index-key.md | 4 ++++ lib/rules/no-array-index-key.js | 1 + tests/lib/rules/no-array-index-key.js | 7 +++++++ 4 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e5d07e8a8..fac36a0f3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange ## Unreleased +### Fixed +* [`no-array-index-key`]: consider flatMap ([#3530][] @k-yle) + +[#3530]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3530 + ## [7.32.2] - 2023.01.28 ### Fixed diff --git a/docs/rules/no-array-index-key.md b/docs/rules/no-array-index-key.md index f9481156a2..37f2652d93 100644 --- a/docs/rules/no-array-index-key.md +++ b/docs/rules/no-array-index-key.md @@ -45,6 +45,10 @@ things.findIndex((thing, index) => { otherThings.push(); }); +things.flatMap((thing, index) => ( + +)); + things.reduce((collection, thing, index) => ( collection.concat() ), []); diff --git a/lib/rules/no-array-index-key.js b/lib/rules/no-array-index-key.js index 0e641b58fb..08ecd7a6a9 100644 --- a/lib/rules/no-array-index-key.js +++ b/lib/rules/no-array-index-key.js @@ -65,6 +65,7 @@ module.exports = { filter: 1, find: 1, findIndex: 1, + flatMap: 1, forEach: 1, map: 1, reduce: 2, diff --git a/tests/lib/rules/no-array-index-key.js b/tests/lib/rules/no-array-index-key.js index e765d001ab..dc5364f47c 100644 --- a/tests/lib/rules/no-array-index-key.js +++ b/tests/lib/rules/no-array-index-key.js @@ -93,6 +93,9 @@ ruleTester.run('no-array-index-key', rule, { { code: 'foo.map((bar, i) => )', }, + { + code: 'foo.flatMap((a) => )', + }, { code: 'foo.reduce((a, b) => a.concat(), [])', }, @@ -226,6 +229,10 @@ ruleTester.run('no-array-index-key', rule, { code: 'foo.reduce((a, b, i) => a.concat(), [])', errors: [{ messageId: 'noArrayIndex' }], }, + { + code: 'foo.flatMap((a, i) => )', + errors: [{ messageId: 'noArrayIndex' }], + }, { code: 'foo.reduceRight((a, b, i) => a.concat(), [])', errors: [{ messageId: 'noArrayIndex' }],