unicorn/no-await-in-promise-methods 正しさ
何をするか
Promise メソッドの引数に await を使用することを禁止します
なぜ悪いのか
Promise.all()、Promise.allSettled()、Promise.any()、または Promise.race() に渡されたプロミスに対して await を使用することは、おそらく誤りです。
例
このルールにおいて不適切なコードの例:
javascript
async function foo() {
// ❌ await を使ってはいけません
Promise.all([await promise, anotherPromise]);
Promise.allSettled([await promise, anotherPromise]);
Promise.any([await promise, anotherPromise]);
Promise.race([await promise, anotherPromise]);
}このルールにおいて正しいコードの例:
javascript
async function foo() {
// ✅ await を使わないでください
Promise.all([promise, anotherPromise]);
Promise.allSettled([promise, anotherPromise]);
Promise.any([promise, anotherPromise]);
Promise.race([promise, anotherPromise]);
}使い方
設定ファイルまたは CLI でこのルールを有効化するには、以下のようにします:
json
{
"rules": {
"unicorn/no-await-in-promise-methods": "error"
}
}bash
oxlint --deny unicorn/no-await-in-promise-methods