💼 This rule is enabled in the ✅ recommended
config.
🔧 This rule is automatically fixable by the --fix
CLI option.
This rule enforces the use of Math.min()
and Math.max()
functions instead of ternary expressions when performing simple comparisons, such as selecting the minimum or maximum value between two or more options.
By replacing ternary expressions with these functions, the code becomes more concise, easier to understand, and less prone to errors. It also enhances consistency across the codebase, ensuring that the same approach is used for similar operations, ultimately improving the overall readability and maintainability of the code.
height > 50 ? 50 : height; // ❌
Math.min(height, 50); // ✅
height >= 50 ? 50 : height; // ❌
Math.min(height, 50); // ✅
height < 50 ? height : 50; // ❌
Math.min(height, 50); // ✅
height <= 50 ? height : 50; // ❌
Math.min(height, 50); // ✅
height > 50 ? height : 50; // ❌
Math.max(height, 50); // ✅
height >= 50 ? height : 50; // ❌
Math.max(height, 50); // ✅
height < 50 ? 50 : height; // ❌
Math.max(height, 50); // ✅
height <= 50 ? 50 : height; // ❌
Math.max(height, 50); // ✅