Skip to content

useMathMinMax

biome.json
{
"linter": {
"rules": {
"nursery": {
"useMathMinMax": "error"
}
}
}
}

Prefer Math.min() and Math.max() over ternaries for simple comparisons.

Replacing ternary comparisons like a > b ? b : a with Math.min(a, b) makes the intent clearer and keeps equivalent min/max comparisons consistent across a codebase.

This rule only targets straightforward min/max ternaries and ignores operands that are obviously not numeric, such as bigint and Date values.

height > 50 ? 50 : height;
code-block.js:1:1 lint/nursery/useMathMinMax  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This ternary is selecting the smaller of the same two operands, which can be simplified.

> 1 │ height > 50 ? 50 : height;
^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

Dedicated min/max functions like Math.min() are clearer and more concise for this purpose.

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: Use Math.min() instead.

1 - height·>·50·?·50·:·height;
1+ Math.min(height·,·50);
2 2

height < 50 ? 50 : height;
code-block.js:1:1 lint/nursery/useMathMinMax  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This ternary is selecting the larger of the same two operands, which can be simplified.

> 1 │ height < 50 ? 50 : height;
^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

Dedicated min/max functions like Math.max() are clearer and more concise for this purpose.

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: Use Math.max() instead.

1 - height·<·50·?·50·:·height;
1+ Math.max(height·,·50);
2 2

Math.min(height, 50);
Math.max(height, 50);
foo ? foo : bar;