Skip to content

useFlatMathMinMax (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"useFlatMathMinMax": "error"
}
}
}
}

Prefer flat Math.min() and Math.max() calls over nested calls of the same method.

Math.min() and Math.max() accept any number of arguments, so nesting the same call is unnecessary.

const biggest = Math.max(Math.max(a, b), c);
code-block.js:1:17 lint/nursery/useFlatMathMinMax  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This Math.max() call contains another call to the same method.

> 1 │ const biggest = Math.max(Math.max(a, b), c);
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ Math.max() accepts any number of arguments, so the nested call is unnecessary.

ℹ 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.

ℹ Unsafe fix: Flatten the nested Math.max() calls.

1 │ const·biggest·=·Math.max(Math.max(a,·b),·c);
│ --------- -
const smallest = Math.min(a, Math.min(b, c));
code-block.js:1:18 lint/nursery/useFlatMathMinMax  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This Math.min() call contains another call to the same method.

> 1 │ const smallest = Math.min(a, Math.min(b, c));
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ Math.min() accepts any number of arguments, so the nested call is unnecessary.

ℹ 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.

ℹ Unsafe fix: Flatten the nested Math.min() calls.

1 │ const·smallest·=·Math.min(a,·Math.min(b,·c));
│ --------- -
const biggest = Math.max(a, b, c);
const clamped = Math.max(Math.min(value, upper), lower);