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
Copy file name to clipboardExpand all lines: README.md
+109-23
Original file line number
Diff line number
Diff line change
@@ -116,7 +116,8 @@ For example:
116
116
117
117
You can use `parserOptions.parser` property to specify a custom parser to parse `<script>` tags.
118
118
Other properties than parser would be given to the specified parser.
119
-
For example:
119
+
120
+
For example in `eslint.config.js`:
120
121
121
122
```js
122
123
importtsParserfrom"@typescript-eslint/parser";
@@ -133,7 +134,20 @@ export default [
133
134
];
134
135
```
135
136
136
-
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.
137
+
For example in `.eslintrc.*`:
138
+
139
+
```json
140
+
{
141
+
"parser": "svelte-eslint-parser",
142
+
"parserOptions": {
143
+
"parser": "@typescript-eslint/parser"
144
+
}
145
+
}
146
+
```
147
+
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`:
137
151
138
152
```js
139
153
importtsParserfrom"@typescript-eslint/parser";
@@ -164,10 +178,38 @@ export default [
164
178
];
165
179
```
166
180
181
+
For example in `.eslintrc.*`:
182
+
183
+
```js
184
+
module.exports= {
185
+
// ...
186
+
parser:"@typescript-eslint/parser",
187
+
parserOptions: {
188
+
// ...
189
+
project:"path/to/your/tsconfig.json",
190
+
extraFileExtensions: [".svelte"], // This is a required setting in `@typescript-eslint/parser` v4.24.0.
191
+
},
192
+
overrides: [
193
+
{
194
+
files: ["*.svelte"],
195
+
parser:"svelte-eslint-parser",
196
+
// Parse the `<script>` in `.svelte` as TypeScript by adding the following configuration.
197
+
parserOptions: {
198
+
parser:"@typescript-eslint/parser",
199
+
},
200
+
},
201
+
// ...
202
+
],
203
+
// ...
204
+
};
205
+
```
206
+
167
207
#### Multiple parsers
168
208
169
209
If you want to switch the parser for each lang, specify the object.
170
210
211
+
For example in `eslint.config.js`:
212
+
171
213
```js
172
214
importtsParserfrom"@typescript-eslint/parser";
173
215
importespreefrom"espree";
@@ -188,34 +230,27 @@ export default [
188
230
];
189
231
```
190
232
191
-
#### Parser module name
192
-
193
-
When using JavaScript configuration (`eslint.config.js`), you can also give the parser module name.
233
+
For example in `.eslintrc.*`:
194
234
195
-
```js
196
-
exportdefault [
197
-
{
198
-
files: ["**/*.svelte", "*.svelte"],
199
-
languageOptions: {
200
-
parser: svelteParser,
201
-
parserOptions: {
202
-
// Single parser
203
-
parser:"@typescript-eslint/parser",
204
-
// Multiple parser
205
-
parser: {
206
-
js:"espree",
207
-
ts:"@typescript-eslint/parser",
208
-
},
209
-
},
210
-
},
211
-
},
212
-
];
235
+
```json
236
+
{
237
+
"parser": "svelte-eslint-parser",
238
+
"parserOptions": {
239
+
"parser": {
240
+
"ts": "@typescript-eslint/parser",
241
+
"js": "espree",
242
+
"typescript": "@typescript-eslint/parser"
243
+
}
244
+
}
245
+
}
213
246
```
214
247
215
248
### parserOptions.svelteFeatures
216
249
217
250
You can use `parserOptions.svelteFeatures` property to specify how to parse related to Svelte features. For example:
218
251
252
+
For example in `eslint.config.js`:
253
+
219
254
```js
220
255
exportdefault [
221
256
{
@@ -236,6 +271,23 @@ export default [
236
271
];
237
272
```
238
273
274
+
For example in `.eslintrc.*`:
275
+
276
+
```jsonc
277
+
{
278
+
"parser":"svelte-eslint-parser",
279
+
"parserOptions": {
280
+
"svelteFeatures": {
281
+
/* -- Experimental Svelte Features -- */
282
+
/* It may be changed or removed in minor versions without notice. */
283
+
// Whether to parse the `generics` attribute.
284
+
// See https://github.com/sveltejs/rfcs/pull/38
285
+
"experimentalGenerics":false,
286
+
},
287
+
},
288
+
}
289
+
```
290
+
239
291
### Runes support
240
292
241
293
**_This is an experimental feature. It may be changed or removed in minor versions without notice._**
@@ -244,6 +296,8 @@ If you install Svelte v5 the parser will be able to parse runes, and will also b
244
296
245
297
When using this mode in an ESLint configuration, it is recommended to set it per file pattern as below.
0 commit comments