Skip to content

unicorn/no-magic-array-flat-depth Restriction ​

What it does ​

Disallow magic numbers for Array.prototype.flat depth.

Why is this bad? ​

Magic numbers are hard to understand and maintain. When calling Array.prototype.flat, it is usually called with 1 or infinity. If you are using a different number, it is better to add a comment explaining the depth.

Example ​

Examples of incorrect code for this rule:

javascript
array.flat(2);
array.flat(20);

Examples of correct code for this rule:

javascript
array.flat(2 /* explanation */);
array.flat(1);
array.flat();
array.flat(Infinity);

References ​

Released under the MIT License.