Skip to content
← Back to rules

unicorn/no-unnecessary-await 正确性

This rule is turned on by default.
🛠️ An auto-fix is available for this rule for some violations.

它做了什么

禁止对非 Promise 值使用 await

为什么这是不好的?

await 操作符只能用于 Promise 值。

示例

此规则的 错误 代码示例:

javascript
async function bad() {
  await await promise;
}

此规则的 正确 代码示例:

javascript
async function bad() {
  await promise;
}

如何使用

通过配置文件或在 CLI 中启用此规则,可以使用:

json
{
  "rules": {
    "unicorn/no-unnecessary-await": "error"
  }
}
bash
oxlint --deny unicorn/no-unnecessary-await

参考资料