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

JSDoc types are lost in svelte files (typescript-eslint) #533

Open
4 tasks done
falco467 opened this issue Jun 11, 2024 · 0 comments · May be fixed by #607
Open
4 tasks done

JSDoc types are lost in svelte files (typescript-eslint) #533

falco467 opened this issue Jun 11, 2024 · 0 comments · May be fixed by #607
Labels
help wanted Extra attention is needed typescript

Comments

@falco467
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?

9.3.0

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

What did you do?

Configuration
import tsEslint from 'typescript-eslint'
import epSvelte from 'eslint-plugin-svelte'
import svelteParser from 'svelte-eslint-parser'

export default [
  ...tsEslint.configs.strictTypeChecked,
  ...epSvelte.configs['flat/recommended'],
  {
    languageOptions: {
      parser: tsEslint.parser,
      parserOptions: {
        project: true,
        programs: false,
        extraFileExtensions: ['.svelte']
      },
    },
  },
  {
    files: ['**/*.svelte'],
    languageOptions: {
      parser: svelteParser,
      parserOptions: {
        parser: tsEslint.parser,
      }
    },
  },
]
<script>
  /** @param {number} x  */
  function test(x) {
    return x+1
  }
</script>

While both .svelte and .js files are scanned by ESLint the same function yields different results:

// test.svelte
<script>
  /** @param {number} x */
  function test(x) {
    return x+1
  }
</script>
// test.js
  /** @param {number} x */
  function test(x) {
    return x+1
  }

npx eslint src

test.js
   2:10  error  'test' is defined but never used     @typescript-eslint/no-unused-vars

test.svelte
    3:12  error  'test' is defined but never used  @typescript-eslint/no-unused-vars
    4:5   error  Unsafe return of an `any` typed value  @typescript-eslint/no-unsafe-return
    5:12  error  Invalid operand for a '+' operation. Operands must each be a number or string. Got `any`  @typescript-eslint/restrict-plus-operands

What did you expect to happen?

I expected the same code to produce the same warnings, irrespective of appearing in a .svelte or .js file.

What actually happened?

It seems like the typescript-eslint parser cannot parse type information from the code in the .svelte files. Maybe the svelte-parser strips JSDoc comments from the code before forwarding it to the typescript parser?

Link to GitHub Repo with Minimal Reproducible Example

https://github.com/falco467/svelte-jsdoc-typescript-example

Additional comments

Migrated from eslint-plugin-svelte since it is a parser problem: sveltejs/eslint-plugin-svelte#767

@ota-meshi ota-meshi added the help wanted Extra attention is needed label Jun 18, 2024
@baseballyama baseballyama linked a pull request Dec 1, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed typescript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants