Vize

vue/no-unused-vars

v-for / v-slot に宣言しているのに使わない変数を検出します。

既定の重大度 プリセット 自動修正 オプション
warning essential, happy-path, nuxt, ecosystem, opinionated なし なし

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

悪い例

ループで使わない index と、スロットで使わない foo を宣言しています。

<template>
  <li v-for="(item, index) in items" :key="item.id">{{ item.name }}</li>
  <template v-slot="{ foo }">
    <span>Hello</span>
  </template>
</template>

良い例

index を参照するか、不要な別名自体を省略し、スロットでは data を表示します。index の key は使用例であり、項目の安定した識別子として推奨するものではありません。

<template>
  <li v-for="(item, index) in items" :key="index">{{ item.name }}</li>
  <li v-for="item in items" :key="item.id">{{ item.name }}</li>
  <template v-slot="{ data }">
    <span>{{ data }}</span>
  </template>
</template>

設定(Vite+)

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

export default defineConfig({}).withVue({
  linter: {
    "preset": "incremental",
    "rules": {
      "vue/no-unused-vars": "warn"
    }
  },
});

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

関連ページ