Skip to content

Commit 79d1fa2

Browse files
authored
Add parser config docs. (#21)
1 parent 1490110 commit 79d1fa2

File tree

2 files changed

+129
-1
lines changed

2 files changed

+129
-1
lines changed

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,69 @@ If you are using [eslint-plugin-svelte3] you need to remove it.
9898

9999
:::
100100

101+
#### Parser Configuration
102+
103+
If you have specified a parser, you need to configure a parser for `.svelte`.
104+
105+
For example, if you are using the `"@typescript-eslint/parser"`, configure it as follows:
106+
107+
```js
108+
module.exports = {
109+
// ...
110+
parser: "@typescript-eslint/parser",
111+
// Add an `overrides` section to add a parser configuration for svelte.
112+
overrides: [
113+
{
114+
files: ["*.svelte"],
115+
parser: "svelte-eslint-parser",
116+
},
117+
],
118+
// ...
119+
}
120+
```
121+
122+
If you want to use TypeScript in `<script>` of `.svelte`, you need to add more `parserOptions` configuration.
123+
124+
```js
125+
module.exports = {
126+
parser: "@typescript-eslint/parser",
127+
overrides: [
128+
{
129+
files: ["*.svelte"],
130+
parser: "svelte-eslint-parser",
131+
// Parse the script in `.svelte` as TypeScript by adding the following configuration.
132+
parserOptions: {
133+
parser: "@typescript-eslint/parser",
134+
},
135+
},
136+
],
137+
}
138+
```
139+
140+
If you have a mix of TypeScript and JavaScript in your project, use a multiple parser configuration.
141+
142+
```js
143+
module.exports = {
144+
parser: "@typescript-eslint/parser",
145+
overrides: [
146+
{
147+
files: ["*.svelte"],
148+
parser: "svelte-eslint-parser",
149+
parserOptions: {
150+
parser: {
151+
// Specify a parser for each lang.
152+
ts: "@typescript-eslint/parser",
153+
js: "espree",
154+
typescript: "@typescript-eslint/parser",
155+
},
156+
},
157+
},
158+
],
159+
}
160+
```
161+
162+
See also [https://github.com/ota-meshi/svelte-eslint-parser#readme](https://github.com/ota-meshi/svelte-eslint-parser#readme).
163+
101164
#### settings["@ota-meshi/svelte"]
102165

103166
You can change the behavior of this plugin with some settings.

docs/user-guide/README.md

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,69 @@ If you are using [eslint-plugin-svelte3] you need to remove it.
5757

5858
:::
5959

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+
60123
#### settings["@ota-meshi/svelte"]
61124

62125
You can change the behavior of this plugin with some settings.
@@ -112,6 +175,8 @@ Example **.vscode/settings.json**:
112175

113176
## :question: FAQ
114177

115-
- TODO
178+
### Parsing the `.svelte` file fails
179+
180+
You should check the [parser configuration](#parser-configuration).
116181

117182
[eslint-plugin-svelte3]: https://github.com/sveltejs/eslint-plugin-svelte3

0 commit comments

Comments
 (0)