Skip to content

require-each-key

Reports an {#each} block with no key ({#each items as item}).

Without a key the block updates the elements in place when the list changes, which keeps stale state in inputs and components and breaks transitions.

To fix, add a key, {#each items as item (item.id)}.

Reported
{#each items as item}
<p>{item}</p>
{/each}
{#each items as item (item.id)}
...
angular:
lint:
rules:
require-each-key: warn # off, warn (default), error
html:
lint:
rules:
require-each-key: warn # off, warn (default), error
svelte:
lint:
rules:
require-each-key: warn # off, warn (default), error
vue:
lint:
rules:
require-each-key: warn # off, warn (default), error

Enabled by the presets: html/eslint-plugin-svelte-recommended.

Suppress one line with sudsy-disable-next-line require-each-key in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
eslint-plugin-svelte require-each-key full