Skip to content

Latest commit

Β 

History

History
47 lines (35 loc) Β· 1.03 KB

File metadata and controls

47 lines (35 loc) Β· 1.03 KB

no-magic-array-flat-depth

πŸ“ 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);