no-magic-array-flat-depth
March 27, 2026 ยท View on GitHub
๐ Disallow a magic number as the depth argument in Array#flat(โฆ)..
๐ผ This rule is enabled in the following configs: โ
recommended, โ๏ธ unopinionated.
When calling Array#flat(depth), the depth argument should normally be 1 or Infinity, otherwise it should be a meaningful variable name or explained with a comment.
Examples
// โ
const foo = array.flat(2);
// โ
const foo = array.flat(99);
// โ
const foo = array.flat();
// โ
const foo = array.flat(Number.POSITIVE_INFINITY);
// โ
const foo = array.flat(Infinity);
// โ
const foo = array.flat(depth);
// โ
const foo = array.flat(/* The depth is always 2 */ 2);