Skip to content

Latest commit

Β 

History

History
87 lines (63 loc) Β· 3.15 KB

File metadata and controls

87 lines (63 loc) Β· 3.15 KB

prefer-modern-math-apis

πŸ“ 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:

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.