prefer-modern-math-apis
March 27, 2026 ยท View on GitHub
๐ Prefer modern Math APIs over legacy patterns.
๐ผ This rule is enabled in the following configs: โ
recommended, โ๏ธ unopinionated.
๐ง This rule is automatically fixable by the --fix CLI option.
Math additions in ES2015:
- Math.sign()
- Math.trunc()
- Math.cbrt()
- Math.expm1()
- Math.log1p()
- Math.log10()
- Math.log2()
- Math.sinh()
- Math.cosh()
- Math.tanh()
- Math.asinh()
- Math.acosh()
- Math.atanh()
- Math.hypot()
- Math.clz32()
- Math.imul()
- Math.fround()
Currently, we only check a few known cases, but we are open to add more patterns.
If you find a suitable case for this rule, please open an issue.
Examples
// โ
Math.log(x) * Math.LOG10E
// โ
Math.LOG10E * Math.log(x)
// โ
Math.log(x) / Math.LN10
// โ
Math.log10(x)
// โ
Math.log(x) * Math.LOG2E
// โ
Math.LOG2E * Math.log(x)
// โ
Math.log(x) / Math.LN2
// โ
Math.log2(x)
// โ
Math.sqrt(a * a + b * b)
// โ
Math.sqrt(a ** 2 + b ** 2)
// โ
Math.hypot(a, b)
// โ
Math.sqrt(x ** 2)
// โ
Math.abs(x)
Separate rule for Math.trunc()
See unicorn/prefer-math-trunc rule.