Skip to content

Scope Manager should return module scope for top level statements #280

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

Closed
4 tasks done
DMartens opened this issue Feb 17, 2023 · 0 comments · Fixed by #292
Closed
4 tasks done

Scope Manager should return module scope for top level statements #280

DMartens opened this issue Feb 17, 2023 · 0 comments · Fixed by #292
Labels
bug Something isn't working

Comments

@DMartens
Copy link

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

  • I'm using eslint-plugin-svelte. (*.svelte file linting does not work with the parser alone. You should also use eslint-plugin-svelte with it.)
  • I'm sure the problem is a parser problem. (If you are not sure, search for the issue in eslint-plugin-svelte repo and open the issue in eslint-plugin-svelte repo if there is no solution.
  • 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.34.0

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

What did you do?

Configuration
{ parserOptions: { sourceType: 'module' } }
<script>
import imported from "mod";
const local = true;
</script>

What did you expect to happen?

When writing an ESLint rule I expect to get a module scope for visitors with selectors ImportDeclaration or VariableDeclaration or any other top-level statement.

What actually happened?

context.getScope returns the global scope and not the expected module scope.

Link to GitHub Repo with Minimal Reproducible Example

https://github.com/DMartens/svelte-eslint-parser-scope-bug
The test is in the scope.js file

Additional comments

The default scope manager and other custom parser / scope manager return a module scope.
They only return the global scope for Program (which for svelte would be the SvelteScriptElement).
I am willing to provide a PR to fix this.

@DMartens DMartens changed the title Scope Manager: Scope Manager: Return module scope for top level statements Feb 17, 2023
@DMartens DMartens changed the title Scope Manager: Return module scope for top level statements Scope Manager should return module scope for top level statements Feb 17, 2023
@ota-meshi ota-meshi added the bug Something isn't working label Feb 17, 2023
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
2 participants