Skip to content
← Back to rules

oxc/approx-constant Suspicious

💡 A suggestion is available for this rule.

它的作用

禁止使用近似常量,而是优先使用 Math 对象中的常量。

这有什么问题?

近似常量不如 Math 对象中的常量准确。 使用 Math 常量可以提高代码可读性和准确性。 更多信息请参见 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math

示例

以下是此规则的错误代码示例:

javascript
let log10e = 0.434294;

以下是此规则的正确代码示例:

javascript
let log10e = Math.LOG10E;

如何使用

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

json
{
  "rules": {
    "oxc/approx-constant": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "oxc/approx-constant": "error",
  },
});
bash
oxlint --deny oxc/approx-constant

版本

此规则是在 v0.1.1 中添加的。

参考