Skip to content
← Back to rules

unicorn/prefer-modern-math-apis Restriction

🚧 An auto-fix is planned for this rule, but not implemented at this time.

What it does ​

Checks for usage of legacy patterns for mathematical operations.

Why is this bad? ​

Modern JavaScript provides more concise and readable alternatives to legacy patterns.

Currently, the following cases are checked:

  • Prefer Math.log10(x) over alternatives
  • Prefer Math.hypot(…) over alternatives

Examples ​

Examples of incorrect code for this rule:

javascript
Math.log(x) * Math.LOG10E;
Math.sqrt(a * a + b * b);

Examples of correct code for this rule:

javascript
Math.log10(x);
Math.hypot(a, b);

How to use ​

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "unicorn/prefer-modern-math-apis": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "unicorn/prefer-modern-math-apis": "error",
  },
});
bash
oxlint --deny unicorn/prefer-modern-math-apis

Version ​

This rule was added in v0.1.1.

References ​