Skip to content
← Back to rules

eslint/prefer-exponentiation-operator Style

🛠️ An auto-fix is available for this rule.

作用

禁止使用 Math.pow,改为使用 ** 运算符。

为什么这不好?

引入于 ES2016 的中缀幂运算符 ** 是标准 Math.pow 函数的另一种写法。中缀表示法通常被认为更易读,因此也更受推荐。

示例

此规则的错误代码示例:

javascript
Math.pow(a, b);

此规则的正确代码示例:

javascript
a ** b;

如何使用

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

json
{
  "rules": {
    "prefer-exponentiation-operator": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "prefer-exponentiation-operator": "error",
  },
});
bash
oxlint --deny prefer-exponentiation-operator

版本

此规则添加于 v0.4.0。

参考资料