Skip to content
← Back to rules

oxc/no-async-await Restriction

作用

不允许使用 async/await

在现代 JavaScript/TypeScript 代码库中,除非有充分理由,否则通常不应使用此规则。

这为什么不好?

此规则适用于不支持 async/await 语法的环境,或者当你希望强制使用 promises 或其他异步模式时。它也可用于保持使用替代异步模式的代码库中的一致性。

示例

此规则的错误代码示例:

javascript
async function foo() {
  await bar();
  return baz();
}

如何使用

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

json
{
  "rules": {
    "oxc/no-async-await": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "oxc/no-async-await": "error",
  },
});
bash
oxlint --deny oxc/no-async-await

版本

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

参考资料