unicorn/no-await-in-promise-methods Correctness
它的作用
禁止在 Promise 方法参数中使用 await。
为什么这不好?
在传递给 Promise.all()、 Promise.allSettled()、Promise.any() 或 Promise.race() 的参数上使用 await 很可能是个错误。
示例
以下是此规则的错误代码示例:
javascript
async function foo() {
Promise.all([await promise, anotherPromise]);
Promise.allSettled([await promise, anotherPromise]);
Promise.any([await promise, anotherPromise]);
Promise.race([await promise, anotherPromise]);
}以下是此规则的正确代码示例:
javascript
async function foo() {
Promise.all([promise, anotherPromise]);
Promise.allSettled([promise, anotherPromise]);
Promise.any([promise, anotherPromise]);
Promise.race([promise, anotherPromise]);
}如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"unicorn/no-await-in-promise-methods": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"unicorn/no-await-in-promise-methods": "error",
},
});bash
oxlint --deny unicorn/no-await-in-promise-methods版本
此规则已在 v0.2.18 中添加。
