You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can use `parserOptions.parser` property to specify a custom parser to parse `<script>` tags.
97
118
Other properties than parser would be given to the specified parser.
98
-
For example:
119
+
120
+
For example in `eslint.config.js`:
121
+
122
+
```js
123
+
importtsParserfrom"@typescript-eslint/parser";
124
+
exportdefault [
125
+
{
126
+
files: ["**/*.svelte", "*.svelte"],
127
+
languageOptions: {
128
+
parser: svelteParser,
129
+
parserOptions: {
130
+
parser: tsParser,
131
+
},
132
+
},
133
+
},
134
+
];
135
+
```
136
+
137
+
For example in `.eslintrc.*`:
99
138
100
139
```json
101
140
{
102
-
"parser": "svelte-eslint-parser",
103
-
"parserOptions": {
104
-
"parser": "@typescript-eslint/parser"
105
-
}
141
+
"parser": "svelte-eslint-parser",
142
+
"parserOptions": {
143
+
"parser": "@typescript-eslint/parser"
144
+
}
106
145
}
107
146
```
108
147
109
-
For example, if you are using the `"@typescript-eslint/parser"`, and if you want to use TypeScript in `<script>` of `.svelte`, you need to add more `parserOptions` configuration.
148
+
If you are using the `"@typescript-eslint/parser"`, and if you want to use TypeScript in `<script>` of `.svelte`, you need to add more `parserOptions` configuration.
149
+
150
+
For example in `eslint.config.js`:
151
+
152
+
```js
153
+
importtsParserfrom"@typescript-eslint/parser";
154
+
exportdefault [
155
+
// ...
156
+
{
157
+
// ...
158
+
languageOptions: {
159
+
parser: tsParser,
160
+
parserOptions: {
161
+
// ...
162
+
project:"path/to/your/tsconfig.json",
163
+
extraFileExtensions: [".svelte"], // This is a required setting in `@typescript-eslint/parser` v4.24.0.
164
+
},
165
+
},
166
+
},
167
+
{
168
+
files: ["**/*.svelte", "*.svelte"],
169
+
languageOptions: {
170
+
parser: svelteParser,
171
+
// Parse the `<script>` in `.svelte` as TypeScript by adding the following configuration.
172
+
parserOptions: {
173
+
parser: tsParser,
174
+
},
175
+
},
176
+
// ...
177
+
},
178
+
];
179
+
```
180
+
181
+
For example in `.eslintrc.*`:
110
182
111
183
```js
112
184
module.exports= {
@@ -129,103 +201,166 @@ module.exports = {
129
201
// ...
130
202
],
131
203
// ...
132
-
}
204
+
};
133
205
```
134
206
135
207
#### Multiple parsers
136
208
137
209
If you want to switch the parser for each lang, specify the object.
138
210
211
+
For example in `eslint.config.js`:
212
+
213
+
```js
214
+
importtsParserfrom"@typescript-eslint/parser";
215
+
importespreefrom"espree";
216
+
exportdefault [
217
+
{
218
+
files: ["**/*.svelte", "*.svelte"],
219
+
languageOptions: {
220
+
parser: svelteParser,
221
+
parserOptions: {
222
+
parser: {
223
+
ts: tsParser,
224
+
js: espree,
225
+
typescript: tsParser,
226
+
},
227
+
},
228
+
},
229
+
},
230
+
];
231
+
```
232
+
233
+
For example in `.eslintrc.*`:
234
+
139
235
```json
140
236
{
141
-
"parser": "svelte-eslint-parser",
142
-
"parserOptions": {
143
-
"parser": {
144
-
"ts": "@typescript-eslint/parser",
145
-
"js": "espree",
146
-
"typescript": "@typescript-eslint/parser"
147
-
}
237
+
"parser": "svelte-eslint-parser",
238
+
"parserOptions": {
239
+
"parser": {
240
+
"ts": "@typescript-eslint/parser",
241
+
"js": "espree",
242
+
"typescript": "@typescript-eslint/parser"
148
243
}
244
+
}
149
245
}
150
246
```
151
247
152
-
#### Parser Object
248
+
###parserOptions.svelteFeatures
153
249
154
-
When using JavaScript configuration (`.eslintrc.js`), you can also give the parser object directly.
250
+
You can use `parserOptions.svelteFeatures` property to specify how to parse related to Svelte features. For example:
0 commit comments