Vize

vue/no-restricted-call-after-await

await の後に制限されたメソッドを呼ぶ箇所を検出します。

既定の重大度 プリセット 自動修正 オプション
warning なし なし なし

適用範囲:Vue SFC のテンプレートと各ブロック。ルールに必要な script の文脈も例に含めています。

悪い例

setup が await の後に onMounted を呼んでいます。

<script lang="ts">
import { defineComponent, onMounted } from "vue";
export default defineComponent({
  async setup() {
    await Promise.resolve();
    onMounted(() => {});
  },
});
</script>
<template>
  <p>ok</p>
</template>

良い例

setup は await なしで onMounted を登録します。

<script lang="ts">
import { defineComponent, onMounted } from "vue";
export default defineComponent({
  setup() {
    onMounted(() => {});
  },
});
</script>
<template>
  <p>ok</p>
</template>

設定(Vite+)

import { defineConfig } from "@vizejs/vite-plugin/vite-plus";

export default defineConfig({}).withVue({
  linter: {
    "preset": "incremental",
    "rules": {
      "vue/no-restricted-call-after-await": "warn"
    },
    "ruleOptions": {
      "vue/no-restricted-call-after-await": [
        {
          "module": "vue",
          "path": "onMounted"
        }
      ]
    }
  },
});

設定したら vp run lint を実行します。

関連ページ