Skip to content

Commit 4cfa42a

Browse files
committed
update docs
1 parent 202f077 commit 4cfa42a

File tree

1 file changed

+109
-23
lines changed

1 file changed

+109
-23
lines changed

README.md

+109-23
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ For example:
116116

117117
You can use `parserOptions.parser` property to specify a custom parser to parse `<script>` tags.
118118
Other properties than parser would be given to the specified parser.
119-
For example:
119+
120+
For example in `eslint.config.js`:
120121

121122
```js
122123
import tsParser from "@typescript-eslint/parser";
@@ -133,7 +134,20 @@ export default [
133134
];
134135
```
135136

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`:
137151

138152
```js
139153
import tsParser from "@typescript-eslint/parser";
@@ -164,10 +178,38 @@ export default [
164178
];
165179
```
166180

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+
167207
#### Multiple parsers
168208

169209
If you want to switch the parser for each lang, specify the object.
170210

211+
For example in `eslint.config.js`:
212+
171213
```js
172214
import tsParser from "@typescript-eslint/parser";
173215
import espree from "espree";
@@ -188,34 +230,27 @@ export default [
188230
];
189231
```
190232

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.*`:
194234

195-
```js
196-
export default [
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+
}
213246
```
214247

215248
### parserOptions.svelteFeatures
216249

217250
You can use `parserOptions.svelteFeatures` property to specify how to parse related to Svelte features. For example:
218251

252+
For example in `eslint.config.js`:
253+
219254
```js
220255
export default [
221256
{
@@ -236,6 +271,23 @@ export default [
236271
];
237272
```
238273

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+
239291
### Runes support
240292

241293
**_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
244296

245297
When using this mode in an ESLint configuration, it is recommended to set it per file pattern as below.
246298

299+
For example in `eslint.config.js`:
300+
247301
```js
248302
export default [
249303
{
@@ -278,6 +332,38 @@ export default [
278332
];
279333
```
280334

335+
For example in `.eslintrc.*`:
336+
337+
```jsonc
338+
{
339+
"overrides": [
340+
{
341+
"files": ["*.svelte"],
342+
"parser": "svelte-eslint-parser",
343+
"parserOptions": {
344+
"parser": "...",
345+
/* ... */
346+
},
347+
},
348+
{
349+
"files": ["*.svelte.js"],
350+
"parser": "svelte-eslint-parser",
351+
"parserOptions": {
352+
/* ... */
353+
},
354+
},
355+
{
356+
"files": ["*.svelte.ts"],
357+
"parser": "svelte-eslint-parser",
358+
"parserOptions": {
359+
"parser": "...(ts parser)...",
360+
/* ... */
361+
},
362+
},
363+
],
364+
}
365+
```
366+
281367
## :computer: Editor Integrations
282368

283369
### Visual Studio Code

0 commit comments

Comments
 (0)