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.
@@ -99,134 +120,155 @@ For example:
99
120
100
121
```json
101
122
{
102
-
"parser": "svelte-eslint-parser",
103
-
"parserOptions": {
104
-
"parser": "@typescript-eslint/parser"
105
-
}
123
+
"parserOptions": {
124
+
"parser": "@typescript-eslint/parser"
125
+
}
106
126
}
107
127
```
108
128
109
129
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.
110
130
111
131
```js
112
-
module.exports= {
132
+
importtsParserfrom"@typescript-eslint/parser";
133
+
exportdefault [
113
134
// ...
114
-
parser:"@typescript-eslint/parser",
115
-
parserOptions: {
135
+
{
116
136
// ...
117
-
project:"path/to/your/tsconfig.json",
118
-
extraFileExtensions: [".svelte"], // This is a required setting in `@typescript-eslint/parser` v4.24.0.
137
+
languageOptions: {
138
+
parser: tsParser,
139
+
parserOptions: {
140
+
// ...
141
+
project:"path/to/your/tsconfig.json",
142
+
extraFileExtensions: [".svelte"], // This is a required setting in `@typescript-eslint/parser` v4.24.0.
143
+
},
144
+
},
119
145
},
120
-
overrides: [
121
-
{
122
-
files: ["*.svelte"],
123
-
parser:"svelte-eslint-parser",
146
+
{
147
+
files: ["**/*.svelte", "*.svelte"],
148
+
languageOptions: {
149
+
parser:svelteParser,
124
150
// Parse the `<script>` in `.svelte` as TypeScript by adding the following configuration.
125
151
parserOptions: {
126
-
parser:"@typescript-eslint/parser",
152
+
parser:tsParser,
127
153
},
128
154
},
129
155
// ...
130
-
],
131
-
// ...
132
-
}
156
+
},
157
+
];
133
158
```
134
159
135
160
#### Multiple parsers
136
161
137
162
If you want to switch the parser for each lang, specify the object.
138
163
139
-
```json
140
-
{
141
-
"parser": "svelte-eslint-parser",
142
-
"parserOptions": {
143
-
"parser": {
144
-
"ts": "@typescript-eslint/parser",
145
-
"js": "espree",
146
-
"typescript": "@typescript-eslint/parser"
147
-
}
148
-
}
149
-
}
164
+
```js
165
+
importtsParserfrom"@typescript-eslint/parser";
166
+
importespreefrom"espree";
167
+
exportdefault [
168
+
{
169
+
files: ["**/*.svelte", "*.svelte"],
170
+
languageOptions: {
171
+
parser: svelteParser,
172
+
parserOptions: {
173
+
parser: {
174
+
ts: tsParser,
175
+
js: espree,
176
+
typescript: tsParser,
177
+
},
178
+
},
179
+
},
180
+
},
181
+
];
150
182
```
151
183
152
-
#### Parser Object
184
+
#### Parser module name
153
185
154
-
When using JavaScript configuration (`.eslintrc.js`), you can also give the parser object directly.
186
+
When using JavaScript configuration (`eslint.config.js`), you can also give the parser module name.
0 commit comments