Skip to content
← Back to rules

promise/spec-only Restriction

作用 ​

禁止使用非标准的 Promise 静态方法。

为什么这不好? ​

非标准的 Promise 可能会带来更多维护工作。

示例 ​

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

js
Promise.done();

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

js
Promise.resolve();

配置 ​

此规则接受一个包含以下属性的配置对象:

allowedMethods ​

type: string[]

default: null

允许使用的 Promise 静态方法列表。

使用方法 ​

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

json
{
  "plugins": ["promise"],
  "rules": {
    "promise/spec-only": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["promise"],
  rules: {
    "promise/spec-only": "error",
  },
});
bash
oxlint --deny promise/spec-only --promise-plugin

版本 ​

此规则在 v0.9.2 中添加。

参考资料 ​