Skip to content
← Back to rules

unicorn/no-thenable 正しさ

This rule is turned on by default.

何を行うか

then プロパティの使用を禁止します

なぜ問題なのか

オブジェクトが「thenable(待機可能)」として定義されている場合、誤って await 式で使われると、問題が発生する可能性があります:

このルールに違反する誤りのあるコードの例:

javascript
async function example() {
  const foo = {
    unicorn: 1,
    then() {},
  };

  const { unicorn } = await foo;

  console.log("after"); //<- これは決して実行されません
}

このルールに従った正しいコードの例:

javascript
async function example() {
  const foo = {
    unicorn: 1,
    bar() {},
  };

  const { unicorn } = await foo;

  console.log("after");
}

使用方法

設定ファイルまたは CLI でこのルールを有効化するには、次のようにします:

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

参照