unicorn/prefer-math-min-max Pedantic
What it does
Prefers use of Math.min()
and Math.max()
instead of ternary expressions when performing simple comparisons for more concise, easier to understand, and less prone to errors.
Examples
Examples of incorrect code for this rule:
javascript
height > 50 ? 50 : height;
height > 50 ? height : 50;
Examples of correct code for this rule:
javascript
Math.min(height, 50);
Math.max(height, 50);
How to use
To enable this rule in the CLI or using the config file, you can use:
bash
oxlint --deny unicorn/prefer-math-min-max
json
{
"rules": {
"unicorn/prefer-math-min-max": "error"
}
}