Skip to content

Latest commit

 

History

History
40 lines (28 loc) · 948 Bytes

no-magic-array-flat-depth.md

File metadata and controls

40 lines (28 loc) · 948 Bytes

Disallow a magic number as the depth argument in Array#flat(…).

💼 This rule is enabled in the ✅ recommended config.

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.

Fail

const foo = array.flat(2);
const foo = array.flat(99);

Pass

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