unicorn/prefer-modern-math-apis Restriction
作用
检查是否使用了用于数学运算的旧式模式。
为什么这不好?
现代 JavaScript 提供了更简洁、更易读的替代方案来取代旧式模式。
目前会检查以下情况:
- 优先使用
Math.log10(x),而不是其他替代写法 - 优先使用
Math.hypot(…),而不是其他替代写法
示例
此规则的错误代码示例:
javascript
Math.log(x) * Math.LOG10E;
Math.sqrt(a * a + b * b);此规则的正确代码示例:
javascript
Math.log10(x);
Math.hypot(a, b);如何使用
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版本
此规则于 v0.1.1 中添加。
