noFlatMapIdentity
このコンテンツはまだ日本語訳がありません。
Diagnostic Category: lint/correctness/noFlatMapIdentity
Since: v1.7.0
Sources:
- Same as:
flat_map_identity
Disallow to use unnecessary callback on flatMap
.
To achieve the same result (flattening an array) more concisely and efficiently, you should use flat
instead.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.js:1:1 lint/correctness/noFlatMapIdentity FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Avoid unnecessary callback in flatMap call.
> 1 │ array.flatMap((arr) => arr);
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ You can just use flat to flatten the array.
ℹ Safe fix: Replace unnecessary flatMap call to flat instead.
1 │ - array.flatMap((arr)·=>·arr);
1 │ + array.flat();
2 2 │
code-block.js:1:1 lint/correctness/noFlatMapIdentity FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Avoid unnecessary callback in flatMap call.
> 1 │ array.flatMap((arr) => {return arr});
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ You can just use flat to flatten the array.
ℹ Safe fix: Replace unnecessary flatMap call to flat instead.
1 │ - array.flatMap((arr)·=>·{return·arr});
1 │ + array.flat();
2 2 │