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
1. Write `overrides.parser` option into your `.eslintrc.*` file.
53
+
1. Write `parser` option into your ESLint Config file.
54
54
2. Use glob patterns or `--ext .svelte` CLI option.
55
55
56
+
### ESLint Config (`eslint.config.js`)
57
+
58
+
```js
59
+
importjsfrom"@eslint/js";
60
+
importsvelteParserfrom"svelte-eslint-parser";
61
+
exportdefault [
62
+
js.configs.recommended,
63
+
{
64
+
files: ["**/*.svelte", "*.svelte"],
65
+
languageOptions: {
66
+
parser: svelteParser,
67
+
},
68
+
},
69
+
];
70
+
```
71
+
72
+
### ESLint Config (`.eslintrc.*`)
73
+
56
74
```json
57
75
{
58
-
"extends": "eslint:recommended",
59
-
"overrides": [
60
-
{
61
-
"files": ["*.svelte"],
62
-
"parser": "svelte-eslint-parser"
63
-
}
64
-
]
76
+
"extends": "eslint:recommended",
77
+
"overrides": [
78
+
{
79
+
"files": ["*.svelte"],
80
+
"parser": "svelte-eslint-parser"
81
+
}
82
+
]
65
83
}
66
84
```
67
85
86
+
### CLI
87
+
68
88
```console
69
89
$ eslint "src/**/*.{js,svelte}"
70
90
# or
@@ -73,24 +93,25 @@ $ eslint src --ext .svelte
73
93
74
94
## 🔧 Options
75
95
76
-
`parserOptions` has the same properties as what [espree](https://github.com/eslint/espree#usage), the default parser of ESLint, is supporting.
96
+
[`parserOptions`] has the same properties as what [espree](https://github.com/eslint/espree#usage), the default parser of ESLint, is supporting.
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