Skip to content

Commit 2e56d7c

Browse files
committed
update
1 parent 9cfcf90 commit 2e56d7c

File tree

3 files changed

+46
-166
lines changed

3 files changed

+46
-166
lines changed

README.md

+20-142
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ You can check it on [Online DEMO](https://sveltejs.github.io/svelte-eslint-parse
88
> Please refer to the README for the version you are using.\
99
> For example, <https://github.com/sveltejs/svelte-eslint-parser/blob/v0.43.0/README.md>
1010
11-
**_Note that this parser has experimental support for Svelte v5, but may break with new versions of Svelte v5._**
12-
1311
[![NPM license](https://img.shields.io/npm/l/svelte-eslint-parser.svg)](https://www.npmjs.com/package/svelte-eslint-parser)
1412
[![NPM version](https://img.shields.io/npm/v/svelte-eslint-parser.svg)](https://www.npmjs.com/package/svelte-eslint-parser)
1513
[![NPM downloads](https://img.shields.io/badge/dynamic/json.svg?label=downloads&colorB=green&suffix=/day&query=$.downloads&uri=https://api.npmjs.org//downloads/point/last-day/svelte-eslint-parser&maxAge=3600)](http://www.npmtrends.com/svelte-eslint-parser)
@@ -41,12 +39,6 @@ It provides many unique check rules by using the template AST.
4139
ESLint plugin for internationalization (i18n) with Svelte.
4240
It provides rules to help internationalization your application created with Svelte.
4341

44-
## ❗ Attention
45-
46-
The [svelte-eslint-parser] can not be used with the [eslint-plugin-svelte3].
47-
48-
[svelte-eslint-parser]: https://github.com/sveltejs/svelte-eslint-parser
49-
5042
## 💿 Installation
5143

5244
```bash
@@ -74,20 +66,6 @@ export default [
7466
];
7567
```
7668

77-
### ESLint Config (`.eslintrc.*`)
78-
79-
```json
80-
{
81-
"extends": "eslint:recommended",
82-
"overrides": [
83-
{
84-
"files": ["*.svelte"],
85-
"parser": "svelte-eslint-parser"
86-
}
87-
]
88-
}
89-
```
90-
9169
### CLI
9270

9371
```console
@@ -101,18 +79,26 @@ $ eslint src --ext .svelte
10179
[`parserOptions`] has the same properties as what [espree](https://github.com/eslint/espree#usage), the default parser of ESLint, is supporting.
10280
For example:
10381

104-
```json
105-
{
106-
"parserOptions": {
107-
"sourceType": "module",
108-
"ecmaVersion": 2021,
109-
"ecmaFeatures": {
110-
"globalReturn": false,
111-
"impliedStrict": false,
112-
"jsx": false
113-
}
114-
}
115-
}
82+
```js
83+
import svelteParser from "svelte-eslint-parser";
84+
export default [
85+
// ...
86+
{
87+
files: ["**/*.svelte", "*.svelte"],
88+
languageOptions: {
89+
parser: svelteParser,
90+
parserOptions: {
91+
sourceType: "module",
92+
ecmaVersion: 2021,
93+
ecmaFeatures: {
94+
globalReturn: false,
95+
impliedStrict: false,
96+
jsx: false,
97+
},
98+
},
99+
},
100+
},
101+
];
116102
```
117103

118104
[`parserOptions`]: https://eslint.org/docs/latest/use/configure/parser#configure-parser-options
@@ -139,17 +125,6 @@ export default [
139125
];
140126
```
141127

142-
For example in `.eslintrc.*`:
143-
144-
```json
145-
{
146-
"parser": "svelte-eslint-parser",
147-
"parserOptions": {
148-
"parser": "@typescript-eslint/parser"
149-
}
150-
}
151-
```
152-
153128
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.
154129

155130
For example in `eslint.config.js`:
@@ -183,32 +158,6 @@ export default [
183158
];
184159
```
185160

186-
For example in `.eslintrc.*`:
187-
188-
```js
189-
module.exports = {
190-
// ...
191-
parser: "@typescript-eslint/parser",
192-
parserOptions: {
193-
// ...
194-
project: "path/to/your/tsconfig.json",
195-
extraFileExtensions: [".svelte"], // This is a required setting in `@typescript-eslint/parser` v4.24.0.
196-
},
197-
overrides: [
198-
{
199-
files: ["*.svelte"],
200-
parser: "svelte-eslint-parser",
201-
// Parse the `<script>` in `.svelte` as TypeScript by adding the following configuration.
202-
parserOptions: {
203-
parser: "@typescript-eslint/parser",
204-
},
205-
},
206-
// ...
207-
],
208-
// ...
209-
};
210-
```
211-
212161
#### Multiple parsers
213162

214163
If you want to switch the parser for each lang, specify the object.
@@ -235,21 +184,6 @@ export default [
235184
];
236185
```
237186

238-
For example in `.eslintrc.*`:
239-
240-
```json
241-
{
242-
"parser": "svelte-eslint-parser",
243-
"parserOptions": {
244-
"parser": {
245-
"ts": "@typescript-eslint/parser",
246-
"js": "espree",
247-
"typescript": "@typescript-eslint/parser"
248-
}
249-
}
250-
}
251-
```
252-
253187
### parserOptions.svelteConfig
254188

255189
If you are using `eslint.config.js`, you can provide a `svelte.config.js` in the `parserOptions.svelteConfig` property.
@@ -289,8 +223,6 @@ export default [
289223
parser: svelteParser,
290224
parserOptions: {
291225
svelteFeatures: {
292-
/* -- Experimental Svelte Features -- */
293-
/* It may be changed or removed in minor versions without notice. */
294226
// This option is for Svelte 5. The default value is `true`.
295227
// If `false`, ESLint will not recognize rune symbols.
296228
// If not configured this option, The parser will try to read the option from `compilerOptions.runes` from `svelte.config.js`.
@@ -303,29 +235,8 @@ export default [
303235
];
304236
```
305237

306-
For example in `.eslintrc.*`:
307-
308-
```jsonc
309-
{
310-
"parser": "svelte-eslint-parser",
311-
"parserOptions": {
312-
"svelteFeatures": {
313-
/* -- Experimental Svelte Features -- */
314-
/* It may be changed or removed in minor versions without notice. */
315-
// This option is for Svelte 5. The default value is `true`.
316-
// If `false`, ESLint will not recognize rune symbols.
317-
// If not configured this option, The parser will try to read the option from `compilerOptions.runes` from `svelte.config.js`.
318-
// If `parserOptions.svelteConfig` is not specified and the file cannot be parsed by static analysis, it will behave as `true`.
319-
"runes": true,
320-
},
321-
},
322-
}
323-
```
324-
325238
### Runes support
326239

327-
**_This is an experimental feature. It may be changed or removed in minor versions without notice._**
328-
329240
If you install Svelte v5 the parser will be able to parse runes, and will also be able to parse `*.js` and `*.ts` files.
330241
If you don't want to use Runes, you may need to configure. Please read [parserOptions.svelteFeatures](#parseroptionssveltefeatures) for more details.
331242

@@ -371,38 +282,6 @@ export default [
371282
];
372283
```
373284

374-
For example in `.eslintrc.*`:
375-
376-
```jsonc
377-
{
378-
"overrides": [
379-
{
380-
"files": ["*.svelte"],
381-
"parser": "svelte-eslint-parser",
382-
"parserOptions": {
383-
"parser": "...",
384-
/* ... */
385-
},
386-
},
387-
{
388-
"files": ["*.svelte.js"],
389-
"parser": "svelte-eslint-parser",
390-
"parserOptions": {
391-
/* ... */
392-
},
393-
},
394-
{
395-
"files": ["*.svelte.ts"],
396-
"parser": "svelte-eslint-parser",
397-
"parserOptions": {
398-
"parser": "...(ts parser)...",
399-
/* ... */
400-
},
401-
},
402-
],
403-
}
404-
```
405-
406285
## :computer: Editor Integrations
407286

408287
### Visual Studio Code
@@ -441,4 +320,3 @@ See the [LICENSE](LICENSE) file for license rights and limitations (MIT).
441320

442321
[Svelte]: https://svelte.dev/
443322
[ESLint]: https://eslint.org/
444-
[eslint-plugin-svelte3]: https://github.com/sveltejs/eslint-plugin-svelte3

src/index.ts

+2-24
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,2 @@
1-
import * as AST from "./ast/index.js";
2-
import { traverseNodes } from "./traverse.js";
3-
import { KEYS } from "./visitor-keys.js";
4-
import { ParseError } from "./errors.js";
5-
export {
6-
parseForESLint,
7-
type StyleContext,
8-
type StyleContextNoStyleElement,
9-
type StyleContextParseError,
10-
type StyleContextSuccess,
11-
type StyleContextUnknownLang,
12-
} from "./parser/index.js";
13-
export * as meta from "./meta.js";
14-
export { name } from "./meta.js";
15-
export type { SvelteConfig } from "./svelte-config/index.js";
16-
17-
export { AST, ParseError };
18-
19-
// Keys
20-
// eslint-disable-next-line @typescript-eslint/naming-convention -- ignore
21-
export const VisitorKeys = KEYS;
22-
23-
// tools
24-
export { traverseNodes };
1+
export * from "./main.js";
2+
export * as default from "./main.js";

src/main.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import * as AST from "./ast/index.js";
2+
import { traverseNodes } from "./traverse.js";
3+
import { KEYS } from "./visitor-keys.js";
4+
import { ParseError } from "./errors.js";
5+
export {
6+
parseForESLint,
7+
type StyleContext,
8+
type StyleContextNoStyleElement,
9+
type StyleContextParseError,
10+
type StyleContextSuccess,
11+
type StyleContextUnknownLang,
12+
} from "./parser/index.js";
13+
export * as meta from "./meta.js";
14+
export { name } from "./meta.js";
15+
export type { SvelteConfig } from "./svelte-config/index.js";
16+
17+
export { AST, ParseError };
18+
19+
// Keys
20+
// eslint-disable-next-line @typescript-eslint/naming-convention -- ignore
21+
export const VisitorKeys = KEYS;
22+
23+
// tools
24+
export { traverseNodes };

0 commit comments

Comments
 (0)