noMagicArrayFlatDepth (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.6.4 - Diagnostic Category:
lint/nursery/noMagicArrayFlatDepth - This rule doesn’t have a fix.
- The default severity of this rule is information.
- Sources:
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noMagicArrayFlatDepth": "error" } } }}Description
Section titled “Description”Disallow unexplained numbers as the depth argument of Array.prototype.flat().
The depth passed to flat()
is usually 1 (the default) or Infinity.
Any other number doesn’t say why the array needs to be flattened to that exact depth.
Store the depth in a variable with a descriptive name, or add a comment inside the parentheses that explains it.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”const items = array.flat(2);code-block.js:1:26 lint/nursery/noMagicArrayFlatDepth ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The depth passed to flat() is an unexplained number.
> 1 │ const items = array.flat(2);
│ ^
2 │
ℹ A bare number doesn't say why the array needs to be flattened to this depth.
ℹ Store the depth in a variable with a descriptive name, or add a comment inside the parentheses that explains it.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
const items = array.flat(99);code-block.js:1:26 lint/nursery/noMagicArrayFlatDepth ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ The depth passed to flat() is an unexplained number.
> 1 │ const items = array.flat(99);
│ ^^
2 │
ℹ A bare number doesn't say why the array needs to be flattened to this depth.
ℹ Store the depth in a variable with a descriptive name, or add a comment inside the parentheses that explains it.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
const items = array.flat();const allItems = array.flat(Infinity);const allValues = array.flat(Number.POSITIVE_INFINITY);const rows = array.flat(depth);const cells = array.flat(/* The grid is always two levels deep. */ 2);Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.