Vize

vue/no-template-key

v-for 用ではない template の key 指定を検出します。

悪い例 · 良い例

既定の重大度: error
プリセット: essential, happy-path, nuxt, ecosystem, opinionated
自動修正: なし。修正内容を確認してください
適用範囲: Vue SFC のテンプレート・ブロック。必要な script の文脈も例に含めています。
オプション: ルール固有のオプションはありません。重大度とプリセットは設定できます。

設定(Vite+)

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

export default defineConfig({
  lint: {
    vize: {
      "preset": "incremental",
      "rules": {
        "vue/no-template-key": "error"
      }
    },
  },
});
vp run lint

悪い

繰り返しではない template に key を指定しています。

<template>
<template :key="section"><div>Details</div></template>
</template>

良い

template の v-for に key を付け、繰り返す各 fragment を識別します。

<template>
<template v-for="item in items" :key="item.id"><div>{{ item.name }}</div></template>
</template>

良い例は上記の設定でこのルールの検出を避ける例です。他のルールでは検出される場合があります。

実装 · 全ルール