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);
How to use
To enable this rule in the CLI or using the config file, you can use:
bash
oxlint --deny unicorn/no-magic-array-flat-depth
json
{
"rules": {
"unicorn/no-magic-array-flat-depth": "error"
}
}