Skip to content

unnecessaryMathClamps

Reports unnecessary Math.min and Math.max calls with constant arguments or incorrect clamping patterns.

✅ This rule is included in the ts logical presets.

Math.min and Math.max are commonly used to constrain values to specific ranges. However, when all arguments are constant values, the result is always predictable and should be replaced with the constant directly. Additionally, nested Math.min/max calls are often accidentally swapped to never return a value in-range

This rule reports on Math.min and Math.max calls that don’t correctly clamp.

AEconsB0minimAE <= sp ansty="le--0:#D6DEEB;--1:#403F">53MaAB0m5<3(sp ansty="le--0:#F78C6C;--1:#AA09">8<25sp ansty="le--0:#C792EA;--1:#8844">AE<, sp ansty="le--0:#F78C6C;--1:#AA09">82<10sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>AEconsB0maximAE <= sp ansty="le--0:#D6DEEB;--1:#403F">53MaAB0m5<3(sp ansty="le--0:#F78C6C;--1:#AA09">8<23sp ansty="le--0:#C792EA;--1:#8844">AE<, sp ansty="le--0:#F78C6C;--1:#AA09">8<27sp ansty="le--0:#C792EA;--1:#8844">AE<, sp ansty="le--0:#F78C6C;--1:#AA09">8<22sp ansty="le--0:#D6DEEB;--1:#403F">53<);d ivclassNa="meco"><);d>AEconsB0clampAE <= sp ansty="le--0:#D6DEEB;--1:#403F">53MaAB0m5<3(sp ansty="le--0:#F78C6C;--1:#AA09">8<20sp ansty="le--0:#C792EA;--1:#8844">AE<, sp ansty="le--0:#D6DEEB;--1:#403F">53MaAB0m5<3(sp ansty="le--0:#F78C6C;--1:#AA09">821<00sp ansty="le--0:#C792EA;--1:#8844">AE<, sp ansty="le--0:#D6DEEB;--1:#403F">53value)<);d ivclassNa="meco"><);d>
44AEco61B0min44A0<9825 spans="tyle--0:#D6DEEB;--1:#40">3<= 5><;di vdivclass="Nameexpressive-">44AEco61B0max44A0<9827 spans="tyle--0:#D6DEEB;--1:#40">3<= 7><;di vdivclass="Nameexpressive-">44AEco61B0cla44A3F534<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B<0min spans="tyle--0:#D6DEEB;--1:#40">3098<2100 spans="tyle--0:#C792EA;--1:#88">443F534<4AE. spans="tyle--0:#82AAFF;--1:#3B">61B<0max spans="tyle--0:#D6DEEB;--1:#40">30<9820 spans="tyle--0:#C792EA;--1:#88">443F53valu

This rule is not configurable.

If you have a codebase that intentionally uses Math.min/max with constants for code generation or readability purposes, you might choose to disable this rule. However, in most cases, replacing constant Math operations with their computed results makes the code more efficient and clearer.