@@ -57,6 +57,69 @@ If you are using [eslint-plugin-svelte3] you need to remove it.
57
57
58
58
:::
59
59
60
+ #### Parser Configuration
61
+
62
+ If you have specified a parser, you need to configure a parser for ` .svelte ` .
63
+
64
+ For example, if you are using the ` "@typescript-eslint/parser" ` , configure it as follows:
65
+
66
+ ``` js
67
+ module .exports = {
68
+ // ...
69
+ parser: " @typescript-eslint/parser" ,
70
+ // Add an `overrides` section to add a parser configuration for svelte.
71
+ overrides: [
72
+ {
73
+ files: [" *.svelte" ],
74
+ parser: " svelte-eslint-parser" ,
75
+ },
76
+ ],
77
+ // ...
78
+ }
79
+ ```
80
+
81
+ If you want to use TypeScript in ` <script> ` of ` .svelte ` , you need to add more ` parserOptions ` configuration.
82
+
83
+ ``` js
84
+ module .exports = {
85
+ parser: " @typescript-eslint/parser" ,
86
+ overrides: [
87
+ {
88
+ files: [" *.svelte" ],
89
+ parser: " svelte-eslint-parser" ,
90
+ // Parse the script in `.svelte` as TypeScript by adding the following configuration.
91
+ parserOptions: {
92
+ parser: " @typescript-eslint/parser" ,
93
+ },
94
+ },
95
+ ],
96
+ }
97
+ ```
98
+
99
+ If you have a mix of TypeScript and JavaScript in your project, use a multiple parser configuration.
100
+
101
+ ``` js
102
+ module .exports = {
103
+ parser: " @typescript-eslint/parser" ,
104
+ overrides: [
105
+ {
106
+ files: [" *.svelte" ],
107
+ parser: " svelte-eslint-parser" ,
108
+ parserOptions: {
109
+ parser: {
110
+ // Specify a parser for each lang.
111
+ ts: " @typescript-eslint/parser" ,
112
+ js: " espree" ,
113
+ typescript: " @typescript-eslint/parser" ,
114
+ },
115
+ },
116
+ },
117
+ ],
118
+ }
119
+ ```
120
+
121
+ See also [ https://github.com/ota-meshi/svelte-eslint-parser#readme ] ( https://github.com/ota-meshi/svelte-eslint-parser#readme ) .
122
+
60
123
#### settings[ "@ota-meshi/svelte "]
61
124
62
125
You can change the behavior of this plugin with some settings.
@@ -112,6 +175,8 @@ Example **.vscode/settings.json**:
112
175
113
176
## :question : FAQ
114
177
115
- - TODO
178
+ ### Parsing the ` .svelte ` file fails
179
+
180
+ You should check the [ parser configuration] ( #parser-configuration ) .
116
181
117
182
[ eslint-plugin-svelte3 ] : https://github.com/sveltejs/eslint-plugin-svelte3
0 commit comments