noFlatMapIdentity
诊断类别:lint/correctness/noFlatMapIdentity
¥Diagnostic Category: lint/correctness/noFlatMapIdentity
自从:v1.7.0
¥Since: v1.7.0
来源:
¥Sources:
-
与以下相同:
flat_map_identity
¥Same as:
flat_map_identity
禁止在 flatMap
上使用不必要的回调。
¥Disallow to use unnecessary callback on flatMap
.
为了更简洁、更有效地实现相同的结果(展平数组),你应该改用 flat
。
¥To achieve the same result (flattening an array) more concisely and efficiently, you should use flat
instead.
¥Examples
¥Invalid
code-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 │
¥Valid
¥Related links