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);