Skip to content

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.

const result = values.flatMap((value) => value);
const result = values.flatMap((item) => {
return item;
});
const result = values.flatMap(function (element) {
return element;
});

This rule is not configurable.

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.