sveltejs / eslint-plugin-svelte

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

Nesting components with Svelte 5 snippet parameters with the same name can cause ESLint errors #871

Open trevorparscal opened 1 day ago

trevorparscal commented 1 day ago

Describe the bug

When components in nested scopes use the same snippet names, ESLint's no-shadow rule detects that the inner scope is shadowing the snippet name from the outer scope.

svelte-issue

While the example shows a contrived use-case, I ran into this pretty quickly once I started creating reusable UI components. I've temporarily disabled ESLint's no-shadow rule, but of course that isn't ideal.

Reproduction

Example with ESLint configuration on GitHub

Example with the same code on REPL

ESLint Error

Logs

[{
    "resource": "/Users/trevorparscal/Sites/svelte-issue/src/routes/+page.svelte",
    "owner": "eslint4",
    "code": {
        "value": "no-shadow",
        "target": {
            "$mid": 1,
            "path": "/docs/latest/rules/no-shadow",
            "scheme": "https",
            "authority": "eslint.org"
        }
    },
    "severity": 8,
    "message": "'icon' is already declared in the upper scope on line 16 column 12.",
    "source": "eslint",
    "startLineNumber": 22,
    "startColumn": 13,
    "endLineNumber": 22,
    "endColumn": 17
},{
    "resource": "/Users/trevorparscal/Sites/svelte-issue/src/routes/+page.svelte",
    "owner": "eslint4",
    "code": {
        "value": "no-shadow",
        "target": {
            "$mid": 1,
            "path": "/docs/latest/rules/no-shadow",
            "scheme": "https",
            "authority": "eslint.org"
        }
    },
    "severity": 8,
    "message": "'label' is already declared in the upper scope on line 13 column 12.",
    "source": "eslint",
    "startLineNumber": 27,
    "startColumn": 13,
    "endLineNumber": 27,
    "endColumn": 18
}]

System Info

System:
    OS: macOS 15.0.1
    CPU: (8) arm64 Apple M1
    Memory: 66.11 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node
    npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm
    bun: 1.1.12 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 129.1.70.123
    Chrome: 126.0.6478.127
    Safari: 18.0.1
  npmPackages:
    svelte: ^5.0.0-next.1 => 5.0.0-next.264

Severity

annoyance

ota-meshi commented 5 hours ago

I think that rule correctly reports shadowing, why do you think it's not ideal?