Skip to content

Commit fbad19b

Browse files
authored
chore: update README for v1 (#665)
1 parent 28ad302 commit fbad19b

File tree

1 file changed

+91
-128
lines changed

1 file changed

+91
-128
lines changed

Diff for: README.md

+91-128
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
# svelte-eslint-parser
2-
3-
[Svelte] parser for [ESLint].
4-
You can check it on [Online DEMO](https://sveltejs.github.io/svelte-eslint-parser/playground).
5-
6-
> [!NOTE]
7-
> This README is in development.\
8-
> Please refer to the README for the version you are using.\
9-
> For example, <https://github.com/sveltejs/svelte-eslint-parser/blob/v0.43.0/README.md>
10-
111
[![NPM license](https://img.shields.io/npm/l/svelte-eslint-parser.svg)](https://www.npmjs.com/package/svelte-eslint-parser)
122
[![NPM version](https://img.shields.io/npm/v/svelte-eslint-parser.svg)](https://www.npmjs.com/package/svelte-eslint-parser)
133
[![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)
@@ -18,47 +8,64 @@ You can check it on [Online DEMO](https://sveltejs.github.io/svelte-eslint-parse
188
[![Build Status](https://github.com/sveltejs/svelte-eslint-parser/workflows/CI/badge.svg?branch=main)](https://github.com/sveltejs/svelte-eslint-parser/actions?query=workflow%3ACI)
199
[![Coverage Status](https://coveralls.io/repos/github/sveltejs/svelte-eslint-parser/badge.svg?branch=main)](https://coveralls.io/github/sveltejs/svelte-eslint-parser?branch=main)
2010

21-
## ⤴️ Motivation
11+
<div align="center">
12+
13+
# svelte-eslint-parser
14+
15+
## [Svelte](https://svelte.dev/) parser for [ESLint](https://eslint.org/).
16+
17+
[Live DEMO](https://sveltejs.github.io/svelte-eslint-parser/playground)
18+
[Discord](https://svelte.dev/chat)
2219

23-
The [svelte-eslint-parser] aims to make it easy to create your own ESLint rules for [Svelte].
20+
</div>
2421

25-
The [`eslint-plugin-svelte`] is an ESLint plugin that uses the [svelte-eslint-parser]. I have already [implemented some rules].
22+
## Motivation
2623

27-
[`eslint-plugin-svelte`]: https://github.com/sveltejs/eslint-plugin-svelte
28-
[implemented some rules]: https://sveltejs.github.io/eslint-plugin-svelte/rules/
24+
The `svelte-eslint-parser` aims to make it easy to create your own ESLint rules for [Svelte](https://svelte.dev/).
25+
26+
[eslint-plugin-svelte](https://github.com/sveltejs/eslint-plugin-svelte) is an ESLint plugin built upon this parser, and it already [implements some rules](https://sveltejs.github.io/eslint-plugin-svelte/rules/).
2927

3028
### ESLint Plugins Using svelte-eslint-parser
3129

3230
#### [eslint-plugin-svelte](https://sveltejs.github.io/eslint-plugin-svelte/)
3331

3432
ESLint plugin for Svelte.
35-
It provides many unique check rules by using the template AST.
33+
Provides a variety of template-based checks using the Svelte AST.
3634

3735
#### [@intlify/eslint-plugin-svelte](https://github.com/intlify/eslint-plugin-svelte)
3836

39-
ESLint plugin for internationalization (i18n) with Svelte.
40-
It provides rules to help internationalization your application created with Svelte.
37+
ESLint plugin for internationalization (i18n) in Svelte applications, offering helpful i18n-related rules.
38+
39+
---
4140

42-
## 💿 Installation
41+
## Installation
4342

4443
```bash
4544
npm install --save-dev eslint svelte-eslint-parser
4645
```
4746

48-
## 📖 Usage
47+
---
4948

50-
1. Write `parser` option into your ESLint Config file.
51-
2. Use glob patterns or `--ext .svelte` CLI option.
49+
## Usage
5250

5351
### ESLint Config (`eslint.config.js`)
5452

5553
```js
5654
import js from "@eslint/js";
5755
import svelteParser from "svelte-eslint-parser";
56+
5857
export default [
5958
js.configs.recommended,
6059
{
61-
files: ["**/*.svelte", "*.svelte"],
60+
files: [
61+
"**/*.svelte",
62+
"*.svelte",
63+
// Need to specify the file extension for Svelte 5 with rune symbols
64+
"**/*.svelte.js",
65+
"*.svelte.js",
66+
"**/*.svelte.ts",
67+
"*.svelte.ts",
68+
],
6269
languageOptions: {
6370
parser: svelteParser,
6471
},
@@ -68,23 +75,27 @@ export default [
6875

6976
### CLI
7077

71-
```console
72-
$ eslint "src/**/*.{js,svelte}"
73-
# or
74-
$ eslint src --ext .svelte
78+
```bash
79+
eslint "src/**/*.{js,svelte}"
7580
```
7681

77-
## 🔧 Options
82+
---
83+
84+
## Options
85+
86+
The [parserOptions](https://eslint.org/docs/latest/use/configure/parser#configure-parser-options) for this parser generally match what [espree](https://github.com/eslint/espree#usage)—ESLint's default parser—supports.
7887

79-
[`parserOptions`] has the same properties as what [espree](https://github.com/eslint/espree#usage), the default parser of ESLint, is supporting.
8088
For example:
8189

8290
```js
8391
import svelteParser from "svelte-eslint-parser";
92+
8493
export default [
8594
// ...
8695
{
87-
files: ["**/*.svelte", "*.svelte"],
96+
files: [
97+
// Set .svelte/.js/.ts files. See above for more details.
98+
],
8899
languageOptions: {
89100
parser: svelteParser,
90101
parserOptions: {
@@ -101,20 +112,18 @@ export default [
101112
];
102113
```
103114

104-
[`parserOptions`]: https://eslint.org/docs/latest/use/configure/parser#configure-parser-options
105-
106115
### parserOptions.parser
107116

108-
You can use `parserOptions.parser` property to specify a custom parser to parse `<script>` tags.
109-
Other properties than parser would be given to the specified parser.
110-
111-
For example in `eslint.config.js`:
117+
Use the `parserOptions.parser` property to define a custom parser for `<script>` tags. Any additional parser options (besides the parser itself) are passed along to the specified parser.
112118

113119
```js
114120
import tsParser from "@typescript-eslint/parser";
121+
115122
export default [
116123
{
117-
files: ["**/*.svelte", "*.svelte"],
124+
files: [
125+
// Set .svelte/.js/.ts files. See above for more details.
126+
],
118127
languageOptions: {
119128
parser: svelteParser,
120129
parserOptions: {
@@ -125,51 +134,53 @@ export default [
125134
];
126135
```
127136

128-
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+
#### Using TypeScript in `<script>`
129138

130-
For example in `eslint.config.js`:
139+
If you use `@typescript-eslint/parser` for TypeScript within `<script>` of `.svelte` files, additional configuration is needed. For example:
131140

132141
```js
133142
import tsParser from "@typescript-eslint/parser";
143+
134144
export default [
135-
// ...
145+
// Other config for non-Svelte files
136146
{
137-
// ...
138147
languageOptions: {
139148
parser: tsParser,
140149
parserOptions: {
141-
// ...
142150
project: "path/to/your/tsconfig.json",
143-
extraFileExtensions: [".svelte"], // This is a required setting in `@typescript-eslint/parser` v4.24.0.
151+
extraFileExtensions: [".svelte"],
144152
},
145153
},
146154
},
155+
// Svelte config
147156
{
148-
files: ["**/*.svelte", "*.svelte"],
157+
files: [
158+
// Set .svelte/.js/.ts files. See above for more details.
159+
],
149160
languageOptions: {
150161
parser: svelteParser,
151162
// Parse the `<script>` in `.svelte` as TypeScript by adding the following configuration.
152163
parserOptions: {
153164
parser: tsParser,
154165
},
155166
},
156-
// ...
157167
},
158168
];
159169
```
160170

161171
#### Multiple parsers
162172

163-
If you want to switch the parser for each lang, specify the object.
164-
165-
For example in `eslint.config.js`:
173+
To switch parsers for each language, provide an object:
166174

167175
```js
168176
import tsParser from "@typescript-eslint/parser";
169177
import espree from "espree";
178+
170179
export default [
171180
{
172-
files: ["**/*.svelte", "*.svelte"],
181+
files: [
182+
// Set .svelte/.js/.ts files. See above for more details.
183+
],
173184
languageOptions: {
174185
parser: svelteParser,
175186
parserOptions: {
@@ -186,15 +197,16 @@ export default [
186197

187198
### parserOptions.svelteConfig
188199

189-
If you are using `eslint.config.js`, you can provide a `svelte.config.js` in the `parserOptions.svelteConfig` property.
190-
191-
For example:
200+
If you use `eslint.config.js`, you can specify a `svelte.config.js` file via `parserOptions.svelteConfig`.
192201

193202
```js
194203
import svelteConfig from "./svelte.config.js";
204+
195205
export default [
196206
{
197-
files: ["**/*.svelte", "*.svelte"],
207+
files: [
208+
// Set .svelte/.js/.ts files. See above for more details.
209+
],
198210
languageOptions: {
199211
parser: svelteParser,
200212
parserOptions: {
@@ -205,28 +217,28 @@ export default [
205217
];
206218
```
207219

208-
If `parserOptions.svelteConfig` is not specified, some config will be statically parsed from the `svelte.config.js` file.
209-
210-
The `.eslintrc.*` style configuration cannot load `svelte.config.js` because it cannot use ESM. We recommend using the `eslint.config.js` style configuration.
220+
If `parserOptions.svelteConfig` is not set, the parser attempts to statically read some config from `svelte.config.js`.
211221

212222
### parserOptions.svelteFeatures
213223

214-
You can use `parserOptions.svelteFeatures` property to specify how to parse related to Svelte features.
224+
You can configure how Svelte-specific features are parsed via `parserOptions.svelteFeatures`.
215225

216-
For example in `eslint.config.js`:
226+
For example:
217227

218228
```js
219229
export default [
220230
{
221-
files: ["**/*.svelte", "*.svelte"],
231+
files: [
232+
// Set .svelte/.js/.ts files. See above for more details.
233+
],
222234
languageOptions: {
223235
parser: svelteParser,
224236
parserOptions: {
225237
svelteFeatures: {
226-
// This option is for Svelte 5. The default value is `true`.
227-
// If `false`, ESLint will not recognize rune symbols.
228-
// If not configured this option, The parser will try to read the option from `compilerOptions.runes` from `svelte.config.js`.
229-
// If `parserOptions.svelteConfig` is not specified and the file cannot be parsed by static analysis, it will behave as `true`.
238+
// This is for Svelte 5. The default is true.
239+
// If false, ESLint won't recognize rune symbols.
240+
// If not specified, the parser tries to read compilerOptions.runes from `svelte.config.js`.
241+
// If `parserOptions.svelteConfig` is not given and static analysis fails, it defaults to true.
230242
runes: true,
231243
},
232244
},
@@ -235,88 +247,39 @@ export default [
235247
];
236248
```
237249

238-
### Runes support
239-
240-
If you install Svelte v5 the parser will be able to parse runes, and will also be able to parse `*.js` and `*.ts` files.
241-
If you don't want to use Runes, you may need to configure. Please read [parserOptions.svelteFeatures](#parseroptionssveltefeatures) for more details.
242-
243-
When using this mode in an ESLint configuration, it is recommended to set it per file pattern as below.
244-
245-
For example in `eslint.config.js`:
246-
247-
```js
248-
import svelteConfig from "./svelte.config.js";
249-
export default [
250-
{
251-
files: ["**/*.svelte", "*.svelte"],
252-
languageOptions: {
253-
parser: svelteParser,
254-
parserOptions: {
255-
parser: "...",
256-
svelteConfig,
257-
/* ... */
258-
},
259-
},
260-
},
261-
{
262-
files: ["**/*.svelte.js", "*.svelte.js"],
263-
languageOptions: {
264-
parser: svelteParser,
265-
parserOptions: {
266-
svelteConfig,
267-
/* ... */
268-
},
269-
},
270-
},
271-
{
272-
files: ["**/*.svelte.ts", "*.svelte.ts"],
273-
languageOptions: {
274-
parser: svelteParser,
275-
parserOptions: {
276-
parser: "...(ts parser)...",
277-
svelteConfig,
278-
/* ... */
279-
},
280-
},
281-
},
282-
];
283-
```
250+
---
284251

285-
## :computer: Editor Integrations
252+
## Editor Integrations
286253

287254
### Visual Studio Code
288255

289-
Use the [dbaeumer.vscode-eslint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) extension that Microsoft provides officially.
256+
Use the [dbaeumer.vscode-eslint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) extension provided by Microsoft.
290257

291-
You have to configure the `eslint.validate` option of the extension to check `.svelte` files, because the extension targets only `*.js` or `*.jsx` files by default.
292-
293-
Example **.vscode/settings.json**:
258+
By default, it only targets `*.js` and `*.jsx`, so you need to configure `.svelte` file support. For example, in **.vscode/settings.json**:
294259

295260
```json
296261
{
297262
"eslint.validate": ["javascript", "javascriptreact", "svelte"]
298263
}
299264
```
300265

301-
## Usage for Custom Rules / Plugins
302-
303-
- [AST.md](./docs/AST.md) is AST specification. You can check it on the [Online DEMO](https://sveltejs.github.io/svelte-eslint-parser/).
304-
- The parser will generate its own [ScopeManager](https://eslint.org/docs/developer-guide/scope-manager-interface). You can check it on the [Online DEMO](https://sveltejs.github.io/svelte-eslint-parser/scope).
305-
- I have already [implemented some rules] in the [`eslint-plugin-svelte`]. The source code for these rules will be helpful to you.
266+
---
306267

307-
## :beers: Contributing
268+
## Usage for Custom Rules / Plugins
308269

309-
Welcome contributing!
270+
- See [AST.md](./docs/AST.md) for the AST specification. You can explore it on the [Live DEMO](https://sveltejs.github.io/svelte-eslint-parser/).
271+
- This parser generates its own [ScopeManager](https://eslint.org/docs/developer-guide/scope-manager-interface). Check the [Live DEMO](https://sveltejs.github.io/svelte-eslint-parser/scope).
272+
- Several rules are [already implemented] in [`eslint-plugin-svelte`], and their source code can be a helpful reference.
310273

311-
Please use GitHub's Issues/PRs.
274+
---
312275

313-
See also the documentation for the internal mechanism.
276+
## Contributing
314277

315-
- [internal-mechanism.md](./docs/internal-mechanism.md)
278+
Contributions are welcome! Please open an issue or submit a PR on GitHub.
279+
For internal details, see [internal-mechanism.md](./docs/internal-mechanism.md).
316280

317-
## :lock: License
281+
---
318282

319-
See the [LICENSE](LICENSE) file for license rights and limitations (MIT).
283+
## License
320284

321-
[Svelte]: https://svelte.dev/
322-
[ESLint]: https://eslint.org/
285+
See [LICENSE](LICENSE) (MIT) for rights and limitations.

0 commit comments

Comments
 (0)