Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consider flatMap for no-array-index-key #3530

Merged
merged 1 commit into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions docs/rules/no-array-index-key.md
Expand Up @@ -45,6 +45,10 @@ things.findIndex((thing, index) => {
otherThings.push(<Hello key={index} />);
});

things.flatMap((thing, index) => (
<Hello key={index} />
));

things.reduce((collection, thing, index) => (
collection.concat(<Hello key={index} />)
), []);
Expand Down
1 change: 1 addition & 0 deletions lib/rules/no-array-index-key.js
Expand Up @@ -65,6 +65,7 @@ module.exports = {
filter: 1,
find: 1,
findIndex: 1,
flatMap: 1,
forEach: 1,
map: 1,
reduce: 2,
Expand Down
7 changes: 7 additions & 0 deletions tests/lib/rules/no-array-index-key.js
Expand Up @@ -93,6 +93,9 @@ ruleTester.run('no-array-index-key', rule, {
{
code: 'foo.map((bar, i) => <Foo key={String(baz)} />)',
},
{
code: 'foo.flatMap((a) => <Foo key={a} />)',
},
{
code: 'foo.reduce((a, b) => a.concat(<Foo key={b.id} />), [])',
},
Expand Down Expand Up @@ -226,6 +229,10 @@ ruleTester.run('no-array-index-key', rule, {
code: 'foo.reduce((a, b, i) => a.concat(<Foo key={i} />), [])',
errors: [{ messageId: 'noArrayIndex' }],
},
{
code: 'foo.flatMap((a, i) => <Foo key={i} />)',
errors: [{ messageId: 'noArrayIndex' }],
},
{
code: 'foo.reduceRight((a, b, i) => a.concat(<Foo key={i} />), [])',
errors: [{ messageId: 'noArrayIndex' }],
Expand Down