This rule raises an issue when legacy array flattening techniques are used instead of the native Array#flat() method introduced in
ES2019.
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:
flatMap() with an identity function reduce() with concat() or spread operators concat() with apply() or spread syntax _.flatten() 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.
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.
Replace flatMap() with identity function with flat().
const flattened = array.flatMap(x => x); // Noncompliant
const flattened = array.flat();