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

Combination of 'svelte3/named-blocks': true and TypeScript parser does not work #162

Open
compeek opened this issue Jan 17, 2022 · 0 comments

Comments

@compeek
Copy link

compeek commented Jan 17, 2022

I've done a ton of searching and debugging, and I have not have found anybody else reporting this problem, but I think I understand why it's happening, at least.

My goal is to use the svelte3/named-blocks feature while also using the TypeScript parser.

Here's an example .eslint.cjs:

module.exports = {
  root: true,
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: 'tsconfig-svelte.json',
  },
  rules: {
    curly: 'error', // particular rule is not relevant
  },
  overrides: [
    {
      files: '*.svelte',
      plugins: [
        'svelte3',
      ],
      processor: 'svelte3/svelte3',
      settings: {
        'svelte3/named-blocks': true,
        'svelte3/typescript': true,
      },
    },
  ],
};

Relevant paths part of tsconfig.json:

{
  ...
  "include": [
    "src/svelte/**/*.ts",
    "src/svelte/**/*.svelte",
  ],
}

Assume I have a file at src/svelte/routes/index.svelte that I have properly passed to eslint to lint.

When I run eslint, I simply get no output. It doesn't report any errors, so it appears like everything passed. However, if I turn on debug logging in eslint with DEBUG=eslint:* eslint, I see this problem occur after the Svelte processor splits up the file into the named blocks:

  eslint:linter With ConfigArray: [BASE PATH OF MY PROJECT]\src\svelte\routes\index.svelte\0_instance.ts +0ms
  eslint:linter Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: src\svelte\routes\index.svelte\0_instance.ts.
The file must be included in at least one of the projects provided.
  eslint:linter Error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: src\svelte\routes\index.svelte\0_instance.ts.
The file must be included in at least one of the projects provided.

The TypeScript parser complains that it can't find 0_instance.ts (and 1_template.ts and so on), even though you can see that the path should match the includes in my tsconfig.json. I experimented with many combinations of settings and paths, but nothing worked.

It finally dawned on me that TypeScript is probably looking for a real file on disk at src/svelte/routes/index.svelte/0_instance.ts, which of course doesn't actually exist. Sure enough, I finally found mention of this in a more general context in this issue: typescript-eslint/typescript-eslint#3174 (comment)
A little more info in this one: typescript-eslint/typescript-eslint#4360

This appears to mean that typescript-eslint simply does not (will not?) support "virtual files" like those created by the Svelte processor in this plugin when using the named-blocks setting. Any files passed to the TypeScript parser must actually exist on disk.

My knowledge about all this stuff is limited to what I've been able to Google, so I'm not sure what the way to fix this would be. But it would be really great if this scenario was supported.

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

No branches or pull requests

1 participant