Skip to content

Fix .flatmap() description for 'prefer-flat-map' #221

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

Merged
merged 1 commit into from
Nov 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,7 @@ Alternatively you can use a [configuration](#configurations) included with this

### `prefer-flat-map`

Use `.flatMap()` to flatten an array and map the values instead of using
`.flat().map()`.
Use `.flatMap()` to map and then flatten an array instead of using `.map().flat()`.

This rule is auto fixable.

Expand All @@ -293,7 +292,7 @@ This rule is auto fixable.
Code that triggers this rule:

```js
const flattenedAndMapped = array.map((p) => p).flat();
const mappedAndFlattened = array.map((p) => p).flat();

const flatWithDefaultDepth = array.map((r) => r).flat(1);
```
Expand All @@ -307,7 +306,7 @@ const flattened = array.flat();

const mapped = array.map((r) => r + 1);

const mappedThenFlattened = array.flat().map((r) => r + 1);
const flattenedThenMapped = array.flat().map((r) => r + 1);

const flatMappedWithExtra = array.map((r) => r + 1).reverse().flat();

Expand Down