v-for-key
Angular templatesHTMLVue / SvelteVue / Sveltecorrectnessno fixdefault: warnhtml/eslint-plugin-vue-recommended
What it does
Section titled “What it does”Reports a v-for with no :key (or v-bind:key). On a <template> or <slot> the key goes on the child elements; components are left to valid-v-for.
Why it matters
Section titled “Why it matters”Without a key Vue patches the elements in place when the list changes, which keeps stale state in inputs and components and breaks transitions.
To fix, add a :key with a value that is unique to each item.
Example
Section titled “Example”<ul><li v-for="x in xs">a</li><li v-for="x in xs" :key="x.id">b</li><li v-for="x in xs" v-bind:key="x">c</li></ul>Configuration
Section titled “Configuration”angular: lint: rules: v-for-key: warn # off, warn (default), errorhtml: lint: rules: v-for-key: warn # off, warn (default), errorsvelte: lint: rules: v-for-key: warn # off, warn (default), errorvue: lint: rules: v-for-key: warn # off, warn (default), errorEnabled by the presets: html/eslint-plugin-vue-recommended.
Suppress one line with sudsy-disable-next-line v-for-key in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| eslint-plugin-vue | require-v-for-key |
full |