Skip to content

Commit 117e60d

Browse files
authored
fix: support each blocks without an item for require-each-key rule (#961)
1 parent 2c551b2 commit 117e60d

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

.changeset/blue-panthers-run.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-svelte': patch
3+
---
4+
5+
fix: support each blocks without an item

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)