Skip to content

Commit

Permalink
fix: support each blocks without an item for require-each-key rule (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
baseballyama authored Dec 29, 2024
1 parent 2c551b2 commit 117e60d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/blue-panthers-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'eslint-plugin-svelte': patch
---

fix: support each blocks without an item
4 changes: 3 additions & 1 deletion packages/eslint-plugin-svelte/src/rules/require-each-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export default createRule('require-each-key', {
create(context) {
return {
SvelteEachBlock(node: AST.SvelteEachBlock) {
if (node.key == null) {
// No need a `key` if an each blocks without an item
// see: https://svelte.dev/docs/svelte/each#Each-blocks-without-an-item
if (node.context != null && node.key == null) {
context.report({
node,
messageId: 'expectedKey'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"svelte": ">=5.0.0-0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="chess-board">
{#each { length: 8 }, rank}
{#each { length: 8 }}
{rank}
{/each}
{/each}
</div>

0 comments on commit 117e60d

Please sign in to comment.