Skip to content

Commit 953e86c

Browse files
committed
support Each blocks without an item
1 parent ad4e538 commit 953e86c

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

packages/eslint-plugin-svelte/src/rules/require-each-key.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ export default createRule('require-each-key', {
1515
create(context) {
1616
return {
1717
SvelteEachBlock(node: AST.SvelteEachBlock) {
18-
if (node.key == null) {
18+
// NO need a `key` if an each blocks without an item
19+
// see: https://svelte.dev/docs/svelte/each#Each-blocks-without-an-item
20+
if (node.context != null && node.key == null) {
1921
context.report({
2022
node,
2123
messageId: 'expectedKey'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"svelte": ">=5.0.0-0"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div class="chess-board">
2+
{#each { length: 8 }, rank}
3+
{#each { length: 8 }}
4+
{rank}
5+
{/each}
6+
{/each}
7+
</div>

0 commit comments

Comments
 (0)