eslint-plugin-svelte: Linting with flat config (ESLint 9) does not work with TypeScript
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?
9.0.0
What version of eslint-plugin-svelte
are you using?
2.36.0
What did you do?
Configuration
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import eslintPluginSvelte from 'eslint-plugin-svelte';
export default [
{ ignores: ['.svelte-kit'] },
{ languageOptions: { globals: globals.browser } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
...eslintPluginSvelte.configs['flat/recommended'],
];
<script lang="ts">
let count: number = 0;
</script>
{count}
What did you expect to happen?
The linter to be happy
What actually happened?
2:11 error Parsing error: Unexpected token :
Link to GitHub Repo with Minimal Reproducible Example
https://github.com/MathiasWP/eslint-9-svelte-typescript-error
Additional comments
No response
About this issue
- Original URL
- State: open
- Created 3 months ago
- Comments: 18
For completeness, here is a full
eslint
“flat file” configuration that works for Svelte projects that use TypeScript. It also includes Prettier linting.Maybe an example of such a “flat file” config could be added to the doc of
eslint-plugin-svelte
, because so far there are only examples of the “old” type of config file (if I’m not mistaken).This should be added to the readme in the parser configuration section. We also don’t have to import the ts parser see here https://typescript-eslint.io/packages/typescript-eslint/#manually-configuring-our-plugin-and-parser.
I think that it helps you to specify
files
for each config object like below:It because that
typescript-eslint
set['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts']
tofiles
.Using typescript-eslint helper function
config(...)
as below provides the almost same flat-config array as above.eslint.config.js using `config` helper
I found why my config file was not working with ts files in vscode, yet the command line interface worked as expected!
I needed this config line in vscode:
"eslint.experimental.useFlatConfig": true
Thank you so much! This solved the issue for me! 🎉