Skip to content

require-for-track

Angular templatesHTMLVue / SvelteVue / Sveltecorrectnessno fixdefault: error

Reports an @for block with no track expression. Only in .component.html files.

Angular needs the expression to tell the items of the list apart, and it stops the build without it. With a good key it moves the elements when the list changes instead of rebuilding them.

To fix, add ; track item.id (a unique value of the item) to the @for.

Reported
...
<p *ngIf="!a$ | async"></p>
...
@for (x of xs) { <i></i> }
@for (x of xs; track x.id) { <i></i> }
angular:
lint:
rules:
require-for-track: error # off, warn, error (default)
html:
lint:
rules:
require-for-track: error # off, warn, error (default)
svelte:
lint:
rules:
require-for-track: error # off, warn, error (default)
vue:
lint:
rules:
require-for-track: error # off, warn, error (default)

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