Skip to content

Commit abb4871

Browse files
k-yleljharb
authored andcommitted
[Fix] no-array-index-key: consider flatMap
1 parent 66b58dd commit abb4871

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
55

66
## Unreleased
77

8+
### Fixed
9+
* [`no-array-index-key`]: consider flatMap ([#3530][] @k-yle)
10+
11+
[#3530]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3530
12+
813
## [7.32.2] - 2023.01.28
914

1015
### Fixed

docs/rules/no-array-index-key.md

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ things.findIndex((thing, index) => {
4545
otherThings.push(<Hello key={index} />);
4646
});
4747

48+
things.flatMap((thing, index) => (
49+
<Hello key={index} />
50+
));
51+
4852
things.reduce((collection, thing, index) => (
4953
collection.concat(<Hello key={index} />)
5054
), []);

lib/rules/no-array-index-key.js

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ module.exports = {
6565
filter: 1,
6666
find: 1,
6767
findIndex: 1,
68+
flatMap: 1,
6869
forEach: 1,
6970
map: 1,
7071
reduce: 2,

tests/lib/rules/no-array-index-key.js

+7
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ ruleTester.run('no-array-index-key', rule, {
9393
{
9494
code: 'foo.map((bar, i) => <Foo key={String(baz)} />)',
9595
},
96+
{
97+
code: 'foo.flatMap((a) => <Foo key={a} />)',
98+
},
9699
{
97100
code: 'foo.reduce((a, b) => a.concat(<Foo key={b.id} />), [])',
98101
},
@@ -226,6 +229,10 @@ ruleTester.run('no-array-index-key', rule, {
226229
code: 'foo.reduce((a, b, i) => a.concat(<Foo key={i} />), [])',
227230
errors: [{ messageId: 'noArrayIndex' }],
228231
},
232+
{
233+
code: 'foo.flatMap((a, i) => <Foo key={i} />)',
234+
errors: [{ messageId: 'noArrayIndex' }],
235+
},
229236
{
230237
code: 'foo.reduceRight((a, b, i) => a.concat(<Foo key={i} />), [])',
231238
errors: [{ messageId: 'noArrayIndex' }],

0 commit comments

Comments
 (0)