useModernMathApis (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/useModernMathApis - This rule has an unsafe fix.
- The default severity of this rule is warning.
- Sources:
- Same as
unicorn/prefer-modern-math-apis
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useModernMathApis": "error" } } }}Description
Section titled “Description”Use modern Math APIs for common mathematical operations.
Dedicated Math methods express mathematical intent directly and avoid reimplementing standard operations.
This rule recognizes logarithm conversions, sums of squares, and square roots of squared values.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”Math.log(x) * Math.LOG10E;code-block.js:1:1 lint/nursery/useModernMathApis FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This expression manually converts a natural logarithm.
> 1 │ Math.log(x) * Math.LOG10E;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ The dedicated Math API expresses the operation directly.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Use Math.log10() instead.
1 │ - Math.log(x)·*·Math.LOG10E;
1 │ + Math.log10(x);
2 2 │
Math.sqrt(a * a + b * b);code-block.js:1:1 lint/nursery/useModernMathApis FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This expression manually computes the square root of a sum of squares.
> 1 │ Math.sqrt(a * a + b * b);
│ ^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ The dedicated Math API expresses the operation directly.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Use Math.hypot() instead.
1 │ - Math.sqrt(a·*·a·+·b·*·b);
1 │ + Math.hypot(a·,·b);
2 2 │
Math.sqrt(x ** 2);code-block.js:1:1 lint/nursery/useModernMathApis FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This expression manually computes an absolute value.
> 1 │ Math.sqrt(x ** 2);
│ ^^^^^^^^^^^^^^^^^
2 │
ℹ The dedicated Math API expresses the operation directly.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
ℹ Unsafe fix: Use Math.abs() instead.
1 │ - Math.sqrt(x·**·2);
1 │ + Math.abs(x);
2 2 │
Math.log10(x);Math.hypot(a, b);Math.abs(x);Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.