useFlatMathMinMax (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/useFlatMathMinMax - This rule has an unsafe fix.
- The default severity of this rule is warning.
- Sources:
- Same as
unicorn/prefer-flat-math-min-max
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useFlatMathMinMax": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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);Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.