This rule raises an issue when legacy array flattening techniques are used instead of the native Array#flat() method introduced in ES2019.

Why is this an issue?

ES2019 introduced the Array#flat() method as the standard way to flatten arrays. This method is more readable and expressive than legacy techniques.

Before Array#flat(), developers used various workarounds to flatten arrays:

These legacy approaches have several drawbacks:

The native Array#flat() method clearly expresses the intent to flatten an array and is the modern standard approach.

What is the potential impact?

Using legacy flattening techniques makes code harder to read and maintain. The intent to flatten an array is not immediately obvious, which can slow down code reviews and debugging. Additionally, some legacy patterns may have performance implications compared to the optimized native method.

How to fix?

Replace flatMap() with identity function with flat().

Non-compliant code example

const flattened = array.flatMap(x => x); // Noncompliant

Compliant code example

const flattened = array.flat();

Documentation

Standards

Related Rules