sveltejs / eslint-plugin-svelte

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

TypeScript generics defined on the `script` generic attribute appear to be ignored by the plugin. #897

Closed orefalo closed 6 days ago

orefalo commented 3 weeks ago

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

What version of ESLint are you using?

9.13.0

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

2.46.0

What did you do?

TypeScript generics defined on the `script` generic attribute appear to be ignored by the plugin.
// Tree.svelte
<script lang="ts" generics="T">
interface data {
  model: Array<T>;
}

What did you expect to happen?

No errors

What actually happened?

/.../src/lib/Tree.svelte 76:18 error 'T' is not defined no-undef 77:31 error 'T' is not defined no-undef 95:44 error 'T' is not defined no-undef 95:60 error 'T' is not defined no-undef

Link to GitHub Repo with Minimal Reproducible Example

Well, this is a work in progress, but it will do to reproduce the error

  1. clone https://github.com/orefalo/svelte-treeviews
  2. pnpm i
  3. pnpm lint

Additional comments

No response

TGlide commented 1 week ago

Any update on this? Any way I can help?

TGlide commented 1 week ago

Fix:

    {
        files: ['**/*.svelte'],
        languageOptions: {
            parser: svelteParser,
            parserOptions: {
                parser: tsEslint.parser,
                svelteFeatures: {
                    experimentalGenerics: true,
                },
            },
        },
    },
orefalo commented 6 days ago

Nice thank you,

this goes into eslint.config.js (eslint 9)

import ts from 'typescript-eslint';
import svelte from 'eslint-plugin-svelte';

...

  {
    files: ['**/*.svelte'],
    languageOptions: {
      parser: svelte.parser,
      parserOptions: {
        parser: ts.parser,
        svelteFeatures: {
          experimentalGenerics: true
        }
      }
    }
  },
orefalo commented 6 days ago

works like a charm, closing