22import js from '@eslint/js' ;
33import ts from 'typescript-eslint' ;
44import svelte from 'eslint-plugin-svelte' ;
5+ import svelteParser from 'svelte-eslint-parser' ;
56import globals from 'globals' ;
67
78export default ts . config (
89 js . configs . recommended ,
9- ...ts . configs . recommended ,
10+ ...ts . configs . recommendedTypeChecked ,
11+ ...ts . configs . stylisticTypeChecked ,
1012 ...svelte . configs [ 'flat/recommended' ] ,
1113 {
1214 languageOptions : {
@@ -19,39 +21,68 @@ export default ts.config(
1921 }
2022 } ,
2123 {
22- files : [ '**/*.svelte' ] ,
2324 languageOptions : {
25+ parser : ts . parser ,
2426 parserOptions : {
25- parser : ts . parser
26- }
27- }
27+ // ...
28+ project : true ,
29+ extraFileExtensions : [ '.svelte' ] , // This is a required setting in `@typescript-eslint/parser` v4.24.0.
30+ } ,
31+ } ,
32+ } ,
33+ {
34+ files : [ '**/*.svelte' , '*.svelte' ] ,
35+ languageOptions : {
36+ parser : svelteParser ,
37+ // Parse the `<script>` in `.svelte` as TypeScript by adding the following configuration.
38+ parserOptions : {
39+ parser : ts . parser ,
40+ } ,
41+ } ,
2842 } ,
2943 {
3044 rules : {
3145 // Allow explicit any, to avoid type gymnastics
32- "@typescript-eslint/no-explicit-any" : "off" ,
33- "@typescript-eslint/no-unused-vars" : [ "error" , {
34- argsIgnorePattern : "^_" ,
35- caughtErrors : "none" ,
36- } ]
46+ '@typescript-eslint/no-explicit-any' : 'off' ,
47+ '@typescript-eslint/no-unused-vars' : [ 'error' , {
48+ argsIgnorePattern : '^_' ,
49+ caughtErrors : 'none' ,
50+ } ] ,
51+ // Disallow floating promises to avoid random crashes
52+ '@typescript-eslint/no-floating-promises' : 'error' ,
53+ // Single quotes where possible
54+ quotes : [ 'error' , 'single' , { 'avoidEscape' : true , 'allowTemplateLiterals' : false } ] ,
55+ // Allow some `any` expressions since otherwise they seriously mess with tests, or enforce
56+ // strictness in areas where it really doesn't matter (eg error handling)
57+ '@typescript-eslint/no-unsafe-assignment' : 'off' ,
58+ '@typescript-eslint/no-unsafe-argument' : 'off' ,
59+ // Also disable template expression checks, since they're also error handling stuff
60+ // TODO: Enable them at some point when I get around to actually tidying things up
61+ '@typescript-eslint/no-base-to-string' : 'off' ,
62+ '@typescript-eslint/restrict-template-expressions' : 'off' ,
63+ // FIXME: When I get around to hardening the request body validation, enable this rule again
64+ '@typescript-eslint/no-unsafe-member-access' : 'off' ,
65+ // Allow empty functions, as they are useful to silence promise errors
66+ '@typescript-eslint/no-empty-function' : 'off' ,
3767 } ,
3868 } ,
3969 {
4070 ignores : [
41- "**/.DS_Store" ,
42- "**/node_modules" ,
43- "build" ,
44- ".svelte-kit" ,
45- "package" ,
46- "**/.env" ,
47- "**/.env.*" ,
48- "!**/.env.example" ,
49- "**/pnpm-lock.yaml" ,
50- "**/package-lock.json" ,
51- "**/yarn.lock" ,
52- "**/svelte.config.js" ,
53- "**/vitest.config.ts" ,
54- "eslint.config.mjs" ,
71+ '**/.DS_Store' ,
72+ '**/node_modules' ,
73+ 'build' ,
74+ '.svelte-kit' ,
75+ 'package' ,
76+ '**/.env' ,
77+ '**/.env.*' ,
78+ '!**/.env.example' ,
79+ '**/pnpm-lock.yaml' ,
80+ '**/package-lock.json' ,
81+ '**/yarn.lock' ,
82+ '**/svelte.config.js' ,
83+ '**/vitest.config.ts' ,
84+ 'eslint.config.mjs' ,
85+ 'vite.config.ts' ,
5586 ] ,
5687 } ,
5788) ;
0 commit comments