arrayMapIdentities
Reports using
.flatMap()with an identity function that returns its argument unchanged.
✅ This rule is included in the ts logical preset.
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 result = values.flatMap((value) => value);const result = values.flatMap((item) => { return item;});const result = values.flatMap(function (element) { return element;});const result = values.flat();const result = values.flatMap((value) => value.children);const result = values.flatMap((value) => [value, ...value.extras]);const result = values.flatMap((value) => transform(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 ❤️🔥 in Boston by
Josh Goldberg and contributors.