arrayMapIdentities
Reports using
.flatMap()with an identity function that returns its argument unchanged.
✅ This rule is included in the tslogicalandlogicalStrictpresets.
Using .flatMap() with a callback that returns its argument unchanged is equivalent to calling .flat().
The .flat() method is more concise and clearly expresses the intent to flatten an array.
Examples
Section titled “Examples”const const result: any
result = const values: any
values.any
flatMap((value: any
value) => value: any
value);const const result: any
result = const values: any
values.any
flatMap((item: any
item) => { return item: any
item;});const const result: any
result = const values: any
values.any
flatMap(function (element: any
element) { return element: any
element;});const const result: any
result = const values: any
values.any
flat();const const result: any
result = const values: any
values.any
flatMap((value: any
value) => value: any
value.any
children);const const result: any
result = const values: any
values.any
flatMap((value: any
value) => [value: any
value, ...value: any
value.any
extras]);const const result: any
result = const values: any
values.any
flatMap((value: any
value) => const transform: any
transform(value: any
value));Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you are maintaining a codebase that must support environments where .flat() is not available, you may need to disable this rule.
Some older JavaScript environments do not support .flat() or .flatMap() and only polyfill .flatMap(), though this is rare in modern development.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noFlatMapIdentity
Made with ❤️🔥 around the world by
the Flint team and contributors.