Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable defined on a component slot and used on the same element wrongly reported as not defined and not used #356

Closed
2 tasks done
divdavem opened this issue Feb 2, 2023 · 3 comments · Fixed by #358
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@divdavem
Copy link

divdavem commented Feb 2, 2023

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.

What version of ESLint are you using?

8.33.0

What version of eslint-plugin-svelte are you using?

2.15.0

What did you do?

<script lang="ts">
  import MyComponent from "./MyComponent.svelte"
</script>

<MyComponent>
  <span
    slot="something"
    let:myVar
    class:myClass={myVar} />
</MyComponent>

What did you expect to happen?

I expected no eslint error because the myVar variable is actually defined and used.

What actually happened?

I get the following two wrong eslint errors:

8:9: 'myVar' is defined but never used. (no-unused-vars)
9:20: 'myVar' is not defined. (no-undef)

Link to GitHub Repo with Minimal Reproducible Example

https://ota-meshi.github.io/eslint-plugin-svelte/playground/#eJx1Vcty2zgQ/BUVz0FctUeXk0vOue5JlyE4JBHjwQWGshmX/30boEiKlHyS0DMczKOn8VHp0HD1XL0kHc0gJ0u++3GuJJ2rn2d/Ohk3hCin39OvgH+evZzaGNzpXH1/ugG/pwtb4XN19i9Pcyh8jsONT4n3kgby+c/plGwQXJWCY+mN7/LHGbcsz276l+J81JZSAvAr//74KJbP09PPfNM+evWtiqPlVD1/VHM+T/UoErzqKSmZBhT6z7fFpINz+E41JrIWc9kZfVAEE9djp4S6dG/rxdlHpiY45cibYbQkqOpoHgdWbBMr06raBv16FyB7IOc1r4cOSSbLaohh4Cjmsc+IW76OMnlyRqs8BYW/x/KN9xzRAbQ/opDgjwE8vmtHr7MNDfaN5XhwCfUfXI5QSvhdlBuTkO7vUolMJcU13JcO1ghHskd76sHRnMK+LZMKF47RNHc3JgmRFaXJ64NFKHYsmAz516MpkrGYqAKF9V3I0b/68OavGaxtX3O5c8d0kG8BlOk8Ejq6JAaZ0+O2DZHbMp8kcdQyxhysVJUv3LlG/m9EOioMYpz5y0uXSCQaLAg/cp5jabK2JnC0cCmhMQPY4L7+YJ0UabToYRrFMYEURm7NaUrCu8gXsqZRWNPB2DlHDWqUckNUCQyf+dbidO138AXBBMETJIO+zEje2Tzt3B1nUAu/sx4RZ7FqystyZHs2ZNnBxwkzWjHkRCjFc6f+cgwbDgoeXZHyI4wgPdnfrFnPFonBIvOO3xewqFDHcTtDIVldaEPytoO4aQfMmTt2Nce95ao/O+yVp1snazQJl7YsKLvhSuPloHSPdunc63LZ3jhQnsJaG78f2gBJiKTqECyTzzfJ3pLYmQVpQUTpYxi7foUgFoeInQ012QM4v2BH0M/sKo0eVjTiDN2O6q2H0pQ9X2w2oJmhBYFYm3QzM9AJBTRZGL5ohzPveemKaqisUkL1avT8ptLk6mBXJPigBXWAjsbhl5OmYU0Eolr2co1QnJcD+C0hP3WqHo3FA7S6QSEKvXkDUPutmGVhZNseWpUeLVPqqQlvALGPBhU35QnZwmA9UqZkpI1VeOSTqrnNOrFtb9HChtvtgIFwCelGFADF5c2W9aWn2t5AiVq8HMajJdMBxX7S7Xpd4SyEAf55XpCh6xu9ibKlmrf2XkGs2wZdlTlLY9Fh9htRFiP2R/dHcD/KNyOzx6KNk2HbFCTrrUme5txnsuaxhtyoz8//Ab+iZkc=

Additional comments

No response

@ota-meshi
Copy link
Member

ota-meshi commented Feb 3, 2023

Thank you for posting issue.
But I think the rules are working correctly. I think you need to define let:myVar on the parent element (component).

https://svelte.dev/repl/07529de5b7c240e3a75fb51556ea5bce?version=3.55.1

@ota-meshi
Copy link
Member

I misunderstood 😓 I just found out that it behaves differently if we give it a named slot.

https://svelte.dev/repl/3027bc1abe724a3cb474842f1880d6f3?version=3.55.1

@divdavem
Copy link
Author

divdavem commented Feb 6, 2023

@ota-meshi Thank you for fixing this issue, and for doing it so quickly! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants