Skip to content

Commit 548c51c

Browse files
committed
Update doc and parser
1 parent 1866ccf commit 548c51c

File tree

4 files changed

+114
-7
lines changed

4 files changed

+114
-7
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
matrix:
1616
os: [ubuntu-latest]
17-
node: [10, 12, 14]
17+
node: [10, 12, 14, 16]
1818
steps:
1919
- name: Checkout
2020
uses: actions/checkout@v2

docs/started.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ npm install --save-dev eslint @intlify/eslint-plugin-svelte
1717

1818
## :rocket: Usage
1919

20+
### Configuration
21+
2022
Configure your `.eslintrc.*` file.
2123

2224
For example:
@@ -42,6 +44,99 @@ module.export = {
4244

4345
See [the rule list](./rules/README.md)
4446

47+
::: warning ❗ Attention
48+
49+
The `@intlify/eslint-plugin-svelte` can not be used with the [eslint-plugin-svelte3].
50+
If you are using [eslint-plugin-svelte3] you need to remove it.
51+
52+
```diff
53+
"plugins": [
54+
- "svelte3"
55+
]
56+
```
57+
58+
:::
59+
60+
[eslint-plugin-svelte3]: https://github.com/sveltejs/eslint-plugin-svelte3
61+
62+
#### Parser Configuration
63+
64+
If you have specified a parser, you need to configure a parser for `.svelte`.
65+
66+
For example, if you are using the `"@babel/eslint-parser"`, configure it as follows:
67+
68+
```js
69+
module.exports = {
70+
// ...
71+
extends: ['plugin:@ota-meshi/svelte/recommended'],
72+
// ...
73+
parser: '@babel/eslint-parser',
74+
// Add an `overrides` section to add a parser configuration for svelte.
75+
overrides: [
76+
{
77+
files: ['*.svelte'],
78+
parser: 'svelte-eslint-parser'
79+
}
80+
// ...
81+
]
82+
// ...
83+
}
84+
```
85+
86+
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.
87+
88+
```js
89+
module.exports = {
90+
// ...
91+
extends: ['plugin:@ota-meshi/svelte/recommended'],
92+
// ...
93+
parser: '@typescript-eslint/parser',
94+
parserOptions: {
95+
// ...
96+
project: 'path/to/your/tsconfig.json',
97+
extraFileExtensions: ['.svelte'] // This is a required setting in `@typescript-eslint/parser` v4.24.0.
98+
},
99+
overrides: [
100+
{
101+
files: ['*.svelte'],
102+
parser: 'svelte-eslint-parser',
103+
// Parse the `<script>` in `.svelte` as TypeScript by adding the following configuration.
104+
parserOptions: {
105+
parser: '@typescript-eslint/parser'
106+
}
107+
}
108+
// ...
109+
]
110+
// ...
111+
}
112+
```
113+
114+
If you have a mix of TypeScript and JavaScript in your project, use a multiple parser configuration.
115+
116+
```js
117+
module.exports = {
118+
// ...
119+
overrides: [
120+
{
121+
files: ['*.svelte'],
122+
parser: 'svelte-eslint-parser',
123+
parserOptions: {
124+
parser: {
125+
// Specify a parser for each lang.
126+
ts: '@typescript-eslint/parser',
127+
js: 'espree',
128+
typescript: '@typescript-eslint/parser'
129+
}
130+
}
131+
}
132+
// ...
133+
]
134+
// ...
135+
}
136+
```
137+
138+
See also [https://github.com/ota-meshi/svelte-eslint-parser#readme](https://github.com/ota-meshi/svelte-eslint-parser#readme).
139+
45140
### Running ESLint from command line
46141

47142
If you want to run `eslint` from command line, make sure you include the `.svelte` extension using [the `--ext` option](https://eslint.org/docs/user-guide/configuring#specifying-file-extensions-to-lint) or a glob pattern because ESLint targets only `.js` files by default.
@@ -53,6 +148,13 @@ eslint --ext .js,.svelte src
53148
eslint "src/**/*.{js,svelte}"
54149
```
55150

151+
## :flying_saucer: More Plugins
152+
153+
### [@ota-meshi/eslint-plugin-svelte](https://ota-meshi.github.io/eslint-plugin-svelte/)
154+
155+
ESLint plugin for Svelte compatible with `@intlify/eslint-plugin-svelte`.
156+
Use it if you want ESLint to do more checks on your Svelte files.
157+
56158
## :question: FAQ
57159

58160
### What is the "Use the latest svelte-eslint-parser" error?

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
},
2323
"dependencies": {
2424
"debug": "^4.3.1",
25-
"svelte-eslint-parser": "^0.1.0"
25+
"svelte-eslint-parser": "^0.4.1"
2626
},
2727
"peerDependencies": {
2828
"eslint": "^7.0.0",

yarn.lock

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4283,6 +4283,11 @@ eslint-visitor-keys@^2.0.0:
42834283
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.0.0.tgz#21fdc8fbcd9c795cc0321f0563702095751511a8"
42844284
integrity sha512-QudtT6av5WXels9WjIM7qz1XD1cWGvX4gGXvp/zBn9nXG02D0utdU3Em2m/QjTnrsk6bBjmCygl3rmj118msQQ==
42854285

4286+
eslint-visitor-keys@^3.0.0:
4287+
version "3.0.0"
4288+
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.0.0.tgz#e32e99c6cdc2eb063f204eda5db67bfe58bb4186"
4289+
integrity sha512-mJOZa35trBTb3IyRmo8xmKBZlxf+N7OnUl4+ZhJHs/r+0770Wh/LEACE2pqMGMe27G/4y8P2bYGk4J70IC5k1Q==
4290+
42864291
eslint4b@^7.16.0:
42874292
version "7.16.0"
42884293
resolved "https://registry.yarnpkg.com/eslint4b/-/eslint4b-7.16.0.tgz#6bea3e3440814828deef6e5e9e42448603edf3b2"
@@ -10011,13 +10016,13 @@ supports-color@^7.1.0:
1001110016
dependencies:
1001210017
has-flag "^4.0.0"
1001310018

10014-
svelte-eslint-parser@^0.1.0:
10015-
version "0.1.0"
10016-
resolved "https://registry.yarnpkg.com/svelte-eslint-parser/-/svelte-eslint-parser-0.1.0.tgz#56a627892245117ee16ae36d18c6c1a708a663f0"
10017-
integrity sha512-Qi+tqus7uKe9F0yQSdHE4rLLGHqFsopuy94MLV/OVmst+XCcD/fr/QTVNtgD1zmUs2iTAuN028GksIm87WihIg==
10019+
svelte-eslint-parser@^0.4.1:
10020+
version "0.4.1"
10021+
resolved "https://registry.yarnpkg.com/svelte-eslint-parser/-/svelte-eslint-parser-0.4.1.tgz#ac645aea60a3dfa977b2693aaa654210f193ae9a"
10022+
integrity sha512-OoCyDI+0O7BjOCHxLiQMsS6e02T/ahh5u7o+CiQBM4RoChadYn/AfgR9SaIMHL2P+aVToxPnX94sC5e482w/Lg==
1001810023
dependencies:
1001910024
eslint-scope "^5.1.1"
10020-
eslint-visitor-keys "^2.0.0"
10025+
eslint-visitor-keys "^3.0.0"
1002110026
espree "^7.3.1"
1002210027

1002310028
svelte@^3.37.0:

0 commit comments

Comments
 (0)