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

Trouble with no-unused-vars rule #149

Closed
2 tasks done
tschaub opened this issue Jan 17, 2023 · 4 comments · Fixed by #151
Closed
2 tasks done

Trouble with no-unused-vars rule #149

tschaub opened this issue Jan 17, 2023 · 4 comments · Fixed by #151

Comments

@tschaub
Copy link

tschaub commented Jan 17, 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?

v8.32.0

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

0.21.1

What did you do?

Configuration
{
  "extends": [
    "plugin:astro/recommended"
  ],
  "rules": {
    "no-unused-vars": "error"
  },
  "overrides": [
    {
      "files": [
        "*.astro"
      ],
      "parser": "astro-eslint-parser",
      "parserOptions": {
        "extraFileExtensions": [
          ".astro"
        ],
        "ecmaVersion": "latest"
      }
    }
  ]
}
---
import SomeComponent from '../components/SomeComponent.astro';
---

<SomeComponent />

What did you expect to happen?

I was hoping that the Astro plugin would work with the no-unused-vars rule.

What actually happened?

/path/to/src/pages/problem.astro
  2:8  error  'SomeComponent' is defined but never used  no-unused-vars

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-nzoac8?file=README.md

Additional comments

Much like the eslint-plugin-react allows ESLint rules (such as no-unused-vars) to work with JSX, I was hoping that this plugin would allow the same for Astro components. I see that there are integration tests using the no-unused-vars rule, but it looks like those don't cover the use of a variable from a component script in a component template.

@ota-meshi
Copy link
Owner

Thank you for the report.

It can be fixed by doing scope analysis in the parser. I will fix that.

@tschaub
Copy link
Author

tschaub commented Jan 18, 2023

Thank you for the quick fix, @ota-meshi!

@tschaub
Copy link
Author

tschaub commented Apr 29, 2024

@ota-meshi - I've just tried upgrading to the latest plugin and parser versions and this issue came up again (planetlabs/maps#501).

Let me know if I should open a new issue in the eslint-plugin-astro project or in astro-eslint-parser.

@tschaub
Copy link
Author

tschaub commented May 10, 2024

I see that the regression was reported in #378

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants