sveltejs / eslint-plugin-svelte

ESLint plugin for Svelte using AST
https://sveltejs.github.io/eslint-plugin-svelte/
MIT License
296 stars 35 forks source link

svelte/no-template-shadow #831

Closed Shyam-Chen closed 2 months ago

Shyam-Chen commented 2 months ago

Motivation

https://eslint.vuejs.org/rules/no-template-shadow.html

Description

Disallow variable declarations from shadowing variables declared in the outer scope

Examples

<script lang="ts">
  let foo = $state(['bar', 'baz']);
</script>

<!-- ✓ GOOD -->
<ul>
  {#each [1, 2, 3] as num (num)}
    <li>{num}</li>
    <ul>
      {#each [11, 22, 33] as subNum (subNum)}
        <li>{subNum}</li>
      {/each}
    </ul>
  {/each}
</ul>

<!-- ✗ BAD -->
<ul>
  {#each [1, 2, 3] as num (num)}
    <li>{num}</li>
    <ul>
      {#each [11, 22, 33] as num (num)}
        <li>{num}</li>
      {/each}
    </ul>
  {/each}
</ul>

<ul>
  {#each [1, 2, 3] as foo (foo)}
    <li>{foo}</li>
  {/each}
</ul>

Additional comments

No response

ota-meshi commented 2 months ago

This plugin works differently from eslint-plugin-vue, so you can check it with the no-shadow rule.

https://eslint.org/docs/latest/rules/no-shadow

Online Demo