eslint-plugin-svelte 1.1.2 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +346 -51
- package/lib/configs/base.d.ts +13 -0
- package/lib/configs/base.js +15 -0
- package/lib/configs/recommended.d.ts +20 -0
- package/lib/configs/recommended.js +26 -0
- package/lib/index.d.ts +45 -0
- package/lib/index.js +47 -0
- package/lib/processor/index.d.ts +4 -0
- package/lib/processor/index.js +30 -0
- package/lib/rules/button-has-type.d.ts +2 -0
- package/lib/rules/button-has-type.js +96 -0
- package/lib/rules/comment-directive.d.ts +2 -0
- package/lib/rules/comment-directive.js +182 -0
- package/lib/rules/first-attribute-linebreak.d.ts +2 -0
- package/lib/rules/first-attribute-linebreak.js +68 -0
- package/lib/rules/html-quotes.d.ts +2 -0
- package/lib/rules/html-quotes.js +170 -0
- package/lib/rules/indent-helpers/ast.d.ts +6 -0
- package/lib/rules/indent-helpers/ast.js +15 -0
- package/lib/rules/indent-helpers/commons.d.ts +27 -0
- package/lib/rules/indent-helpers/commons.js +56 -0
- package/lib/rules/indent-helpers/es.d.ts +5 -0
- package/lib/rules/indent-helpers/es.js +740 -0
- package/lib/rules/indent-helpers/index.d.ts +3 -0
- package/lib/rules/indent-helpers/index.js +223 -0
- package/lib/rules/indent-helpers/offset-context.d.ts +57 -0
- package/lib/rules/indent-helpers/offset-context.js +196 -0
- package/lib/rules/indent-helpers/svelte.d.ts +5 -0
- package/lib/rules/indent-helpers/svelte.js +380 -0
- package/lib/rules/indent-helpers/ts.d.ts +5 -0
- package/lib/rules/indent-helpers/ts.js +735 -0
- package/lib/rules/indent.d.ts +2 -0
- package/lib/rules/indent.js +47 -0
- package/lib/rules/max-attributes-per-line.d.ts +2 -0
- package/lib/rules/max-attributes-per-line.js +101 -0
- package/lib/rules/mustache-spacing.d.ts +2 -0
- package/lib/rules/mustache-spacing.js +255 -0
- package/lib/rules/no-at-debug-tags.d.ts +2 -0
- package/lib/rules/no-at-debug-tags.js +28 -0
- package/lib/rules/no-at-html-tags.d.ts +2 -0
- package/lib/rules/no-at-html-tags.js +27 -0
- package/lib/rules/no-dupe-else-if-blocks.d.ts +2 -0
- package/lib/rules/no-dupe-else-if-blocks.js +100 -0
- package/lib/rules/no-dupe-style-properties.d.ts +2 -0
- package/lib/rules/no-dupe-style-properties.js +89 -0
- package/lib/rules/no-dynamic-slot-name.d.ts +2 -0
- package/lib/rules/no-dynamic-slot-name.js +76 -0
- package/lib/rules/no-inner-declarations.d.ts +2 -0
- package/lib/rules/no-inner-declarations.js +36 -0
- package/lib/rules/no-not-function-handler.d.ts +2 -0
- package/lib/rules/no-not-function-handler.js +91 -0
- package/lib/rules/no-object-in-text-mustaches.d.ts +2 -0
- package/lib/rules/no-object-in-text-mustaches.js +50 -0
- package/lib/rules/no-shorthand-style-property-overrides.d.ts +2 -0
- package/lib/rules/no-shorthand-style-property-overrides.js +97 -0
- package/lib/rules/no-target-blank.d.ts +2 -0
- package/lib/rules/no-target-blank.js +84 -0
- package/lib/rules/no-unknown-style-directive-property.d.ts +2 -0
- package/lib/rules/no-unknown-style-directive-property.js +65 -0
- package/lib/rules/no-unused-svelte-ignore.d.ts +2 -0
- package/lib/rules/no-unused-svelte-ignore.js +52 -0
- package/lib/rules/no-useless-mustaches.d.ts +2 -0
- package/lib/rules/no-useless-mustaches.js +126 -0
- package/lib/rules/prefer-class-directive.d.ts +2 -0
- package/lib/rules/prefer-class-directive.js +247 -0
- package/lib/rules/prefer-style-directive.d.ts +2 -0
- package/lib/rules/prefer-style-directive.js +155 -0
- package/lib/rules/require-optimized-style-attribute.d.ts +2 -0
- package/lib/rules/require-optimized-style-attribute.js +80 -0
- package/lib/rules/shorthand-attribute.d.ts +2 -0
- package/lib/rules/shorthand-attribute.js +83 -0
- package/lib/rules/shorthand-directive.d.ts +2 -0
- package/lib/rules/shorthand-directive.js +103 -0
- package/lib/rules/spaced-html-comment.d.ts +2 -0
- package/lib/rules/spaced-html-comment.js +84 -0
- package/lib/rules/system.d.ts +2 -0
- package/lib/rules/system.js +71 -0
- package/lib/rules/valid-compile.d.ts +2 -0
- package/lib/rules/valid-compile.js +55 -0
- package/lib/shared/comment-directives.d.ts +21 -0
- package/lib/shared/comment-directives.js +150 -0
- package/lib/shared/index.d.ts +8 -0
- package/lib/shared/index.js +31 -0
- package/lib/shared/svelte-compile-warns/extract-leading-comments.d.ts +4 -0
- package/lib/shared/svelte-compile-warns/extract-leading-comments.js +34 -0
- package/lib/shared/svelte-compile-warns/ignore-comment.d.ts +13 -0
- package/lib/shared/svelte-compile-warns/ignore-comment.js +75 -0
- package/lib/shared/svelte-compile-warns/index.d.ts +24 -0
- package/lib/shared/svelte-compile-warns/index.js +456 -0
- package/lib/shared/svelte-compile-warns/transform/babel.d.ts +5 -0
- package/lib/shared/svelte-compile-warns/transform/babel.js +48 -0
- package/lib/shared/svelte-compile-warns/transform/less.d.ts +4 -0
- package/lib/shared/svelte-compile-warns/transform/less.js +45 -0
- package/lib/shared/svelte-compile-warns/transform/load-module.d.ts +3 -0
- package/lib/shared/svelte-compile-warns/transform/load-module.js +74 -0
- package/lib/shared/svelte-compile-warns/transform/postcss.d.ts +4 -0
- package/lib/shared/svelte-compile-warns/transform/postcss.js +43 -0
- package/lib/shared/svelte-compile-warns/transform/sass.d.ts +4 -0
- package/lib/shared/svelte-compile-warns/transform/sass.js +39 -0
- package/lib/shared/svelte-compile-warns/transform/stylus.d.ts +4 -0
- package/lib/shared/svelte-compile-warns/transform/stylus.js +44 -0
- package/lib/shared/svelte-compile-warns/transform/types.d.ts +6 -0
- package/lib/shared/svelte-compile-warns/transform/types.js +2 -0
- package/lib/shared/svelte-compile-warns/transform/typescript.d.ts +5 -0
- package/lib/shared/svelte-compile-warns/transform/typescript.js +44 -0
- package/lib/types-for-node.d.ts +394 -0
- package/lib/types-for-node.js +2 -0
- package/lib/types.d.ts +180 -0
- package/lib/types.js +2 -0
- package/lib/utils/ast-utils.d.ts +48 -0
- package/lib/utils/ast-utils.js +283 -0
- package/lib/utils/css-utils/index.d.ts +3 -0
- package/lib/utils/css-utils/index.js +19 -0
- package/lib/utils/css-utils/resource.d.ts +1 -0
- package/lib/utils/css-utils/resource.js +219 -0
- package/lib/utils/css-utils/style-attribute.d.ts +43 -0
- package/lib/utils/css-utils/style-attribute.js +259 -0
- package/lib/utils/css-utils/template-safe-parser.d.ts +5 -0
- package/lib/utils/css-utils/template-safe-parser.js +13 -0
- package/lib/utils/css-utils/template-tokenize.d.ts +5 -0
- package/lib/utils/css-utils/template-tokenize.js +44 -0
- package/lib/utils/css-utils/utils.d.ts +3 -0
- package/lib/utils/css-utils/utils.js +16 -0
- package/lib/utils/eslint-core.d.ts +13 -0
- package/lib/utils/eslint-core.js +57 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.js +10 -0
- package/lib/utils/lines-and-columns.d.ts +12 -0
- package/lib/utils/lines-and-columns.js +54 -0
- package/lib/utils/regexp.d.ts +2 -0
- package/lib/utils/regexp.js +23 -0
- package/lib/utils/rules.d.ts +2 -0
- package/lib/utils/rules.js +64 -0
- package/package.json +130 -11
- package/CHANGELOG.md +0 -7
- package/index.js +0 -10
- package/processor-options.js +0 -44
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,84 +1,379 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Introduction
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
`eslint-plugin-svelte` is [ESLint] plugin for [Svelte].
|
|
4
|
+
It provides many unique check rules by using the template AST.
|
|
5
|
+
You can check on the [Online DEMO](https://ota-meshi.github.io/eslint-plugin-svelte/playground/).
|
|
5
6
|
|
|
6
|
-
[](https://www.npmjs.com/package/eslint-plugin-svelte)
|
|
8
|
+
[](https://www.npmjs.com/package/eslint-plugin-svelte)
|
|
9
|
+
[](http://www.npmtrends.com/eslint-plugin-svelte)
|
|
10
|
+
[](http://www.npmtrends.com/eslint-plugin-svelte)
|
|
11
|
+
[](http://www.npmtrends.com/eslint-plugin-svelte)
|
|
12
|
+
[](http://www.npmtrends.com/eslint-plugin-svelte)
|
|
13
|
+
[](http://www.npmtrends.com/eslint-plugin-svelte)
|
|
14
|
+
[](https://github.com/ota-meshi/eslint-plugin-svelte/actions?query=workflow%3ACI)
|
|
9
15
|
|
|
10
|
-
|
|
11
|
-
[](https://standardjs.com)
|
|
12
|
-
[](https://github.com/prettier/prettier)
|
|
16
|
+
## :name_badge: What is this plugin?
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
- [How](#how)
|
|
17
|
-
- [Version strategy](#version-strategy)
|
|
18
|
-
- [Usage](#usage)
|
|
19
|
-
- [License](#license)
|
|
18
|
+
[ESLint] plugin for [Svelte].
|
|
19
|
+
It provides many unique check rules using the AST generated by [svelte-eslint-parser].
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
### ❓ Why?
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
[Svelte] has the official [ESLint] plugin the [eslint-plugin-svelte3]. The [eslint-plugin-svelte3] works well enough to check scripts. However, it does not handle the AST of the template, which makes it very difficult for third parties to create their own the [ESLint] rules for the [Svelte].
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
The [svelte-eslint-parser] aims to make it easy to create your own rules for the [Svelte] by allowing the template AST to be used in the rules.
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
### ❗ Attention
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
The [svelte-eslint-parser] and the `eslint-plugin-svelte` can not be used with the [eslint-plugin-svelte3].
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
[svelte-eslint-parser]: https://github.com/ota-meshi/svelte-eslint-parser
|
|
32
|
+
[eslint-plugin-svelte3]: https://github.com/sveltejs/eslint-plugin-svelte3
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
<!--DOCS_IGNORE_START-->
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
2. minor: `eslint-plugin-svelte3@3.2.0` -> `eslint-plugin-svelte@1.2.0`
|
|
37
|
-
3. major:
|
|
38
|
-
1. `eslint-plugin-svelte3@4.3.0` -> `eslint-plugin-svelte@2.3.0`
|
|
39
|
-
2. `eslint-plugin-svelte4@0.4.1` -> `eslint-plugin-svelte@3.4.1`
|
|
40
|
-
3. `eslint-plugin-svelte4@1.5.1` -> `eslint-plugin-svelte@4.5.1`
|
|
36
|
+
## Migration Guide
|
|
41
37
|
|
|
42
|
-
|
|
38
|
+
To migrate from `eslint-plugin-svelte` v1, or `@ota-meshi/eslint-plugin-svelte`, please refer to the [migration guide](https://ota-meshi.github.io/eslint-plugin-svelte/migration/).
|
|
43
39
|
|
|
44
|
-
|
|
40
|
+
## :book: Documentation
|
|
45
41
|
|
|
46
|
-
|
|
42
|
+
See [documents](https://ota-meshi.github.io/eslint-plugin-svelte/).
|
|
43
|
+
|
|
44
|
+
## :cd: Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install --save-dev eslint eslint-plugin-svelte svelte
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
> **Requirements**
|
|
51
|
+
>
|
|
52
|
+
> - ESLint v7.0.0 and above
|
|
53
|
+
> - Node.js v14.17.x, v16.x and above
|
|
54
|
+
|
|
55
|
+
<!--DOCS_IGNORE_END-->
|
|
56
|
+
|
|
57
|
+
## :book: Usage
|
|
58
|
+
|
|
59
|
+
<!--USAGE_SECTION_START-->
|
|
60
|
+
<!--USAGE_GUIDE_START-->
|
|
61
|
+
|
|
62
|
+
### Configuration
|
|
63
|
+
|
|
64
|
+
Use `.eslintrc.*` file to configure rules. See also: [https://eslint.org/docs/user-guide/configuring](https://eslint.org/docs/user-guide/configuring).
|
|
65
|
+
|
|
66
|
+
Example **.eslintrc.js**:
|
|
47
67
|
|
|
48
68
|
```js
|
|
49
69
|
module.exports = {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
70
|
+
extends: [
|
|
71
|
+
// add more generic rule sets here, such as:
|
|
72
|
+
// 'eslint:recommended',
|
|
73
|
+
"plugin:svelte/recommended",
|
|
74
|
+
],
|
|
75
|
+
rules: {
|
|
76
|
+
// override/add rules settings here, such as:
|
|
77
|
+
// 'svelte/rule-name': 'error'
|
|
57
78
|
},
|
|
58
|
-
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
This plugin provides configs:
|
|
83
|
+
|
|
84
|
+
- `plugin:svelte/base` ... Configuration to enable correct Svelte parsing.
|
|
85
|
+
- `plugin:svelte/recommended` ... Above, plus rules to prevent errors or unintended behavior.
|
|
86
|
+
|
|
87
|
+
See [the rule list](https://ota-meshi.github.io/eslint-plugin-svelte/rules/) to get the `rules` that this plugin provides.
|
|
88
|
+
|
|
89
|
+
::: warning ❗ Attention
|
|
90
|
+
|
|
91
|
+
The `eslint-plugin-svelte` can not be used with the [eslint-plugin-svelte3].
|
|
92
|
+
If you are using [eslint-plugin-svelte3] you need to remove it.
|
|
93
|
+
|
|
94
|
+
```diff
|
|
95
|
+
"plugins": [
|
|
96
|
+
- "svelte3"
|
|
97
|
+
]
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
:::
|
|
101
|
+
|
|
102
|
+
#### Parser Configuration
|
|
103
|
+
|
|
104
|
+
If you have specified a parser, you need to configure a parser for `.svelte`.
|
|
105
|
+
|
|
106
|
+
For example, if you are using the `"@babel/eslint-parser"`, configure it as follows:
|
|
107
|
+
|
|
108
|
+
```js
|
|
109
|
+
module.exports = {
|
|
110
|
+
// ...
|
|
111
|
+
extends: ["plugin:svelte/recommended"],
|
|
112
|
+
// ...
|
|
113
|
+
parser: "@babel/eslint-parser",
|
|
114
|
+
// Add an `overrides` section to add a parser configuration for svelte.
|
|
59
115
|
overrides: [
|
|
60
116
|
{
|
|
61
|
-
files: [
|
|
62
|
-
|
|
117
|
+
files: ["*.svelte"],
|
|
118
|
+
parser: "svelte-eslint-parser",
|
|
63
119
|
},
|
|
120
|
+
// ...
|
|
64
121
|
],
|
|
65
|
-
|
|
122
|
+
// ...
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
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.
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
module.exports = {
|
|
130
|
+
// ...
|
|
131
|
+
extends: ["plugin:svelte/recommended"],
|
|
132
|
+
// ...
|
|
133
|
+
parser: "@typescript-eslint/parser",
|
|
134
|
+
parserOptions: {
|
|
66
135
|
// ...
|
|
136
|
+
project: "path/to/your/tsconfig.json",
|
|
137
|
+
extraFileExtensions: [".svelte"], // This is a required setting in `@typescript-eslint/parser` v4.24.0.
|
|
67
138
|
},
|
|
68
|
-
|
|
69
|
-
|
|
139
|
+
overrides: [
|
|
140
|
+
{
|
|
141
|
+
files: ["*.svelte"],
|
|
142
|
+
parser: "svelte-eslint-parser",
|
|
143
|
+
// Parse the `<script>` in `.svelte` as TypeScript by adding the following configuration.
|
|
144
|
+
parserOptions: {
|
|
145
|
+
parser: "@typescript-eslint/parser",
|
|
146
|
+
},
|
|
147
|
+
},
|
|
70
148
|
// ...
|
|
149
|
+
],
|
|
150
|
+
// ...
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
If you have a mix of TypeScript and JavaScript in your project, use a multiple parser configuration.
|
|
155
|
+
|
|
156
|
+
```js
|
|
157
|
+
module.exports = {
|
|
158
|
+
// ...
|
|
159
|
+
overrides: [
|
|
160
|
+
{
|
|
161
|
+
files: ["*.svelte"],
|
|
162
|
+
parser: "svelte-eslint-parser",
|
|
163
|
+
parserOptions: {
|
|
164
|
+
parser: {
|
|
165
|
+
// Specify a parser for each lang.
|
|
166
|
+
ts: "@typescript-eslint/parser",
|
|
167
|
+
js: "espree",
|
|
168
|
+
typescript: "@typescript-eslint/parser",
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
// ...
|
|
173
|
+
],
|
|
174
|
+
// ...
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
See also [https://github.com/ota-meshi/svelte-eslint-parser#readme](https://github.com/ota-meshi/svelte-eslint-parser#readme).
|
|
179
|
+
|
|
180
|
+
#### settings.svelte
|
|
181
|
+
|
|
182
|
+
You can change the behavior of this plugin with some settings.
|
|
183
|
+
|
|
184
|
+
- `ignoreWarnings` (optional) ... Specifies an array of rules that ignore reports in the template.
|
|
185
|
+
For example, set rules on the template that cannot avoid false positives.
|
|
186
|
+
- `compileOptions` (optional) ... Specifies options for Svelte compile. Effects rules that use Svelte compile. The target rules are [svelte/valid-compile](https://ota-meshi.github.io/eslint-plugin-svelte/rules/valid-compile/) and [svelte/no-unused-svelte-ignore](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-unused-svelte-ignore/). **Note that it has no effect on ESLint's custom parser**.
|
|
187
|
+
- `postcss` (optional) ... Specifies options related to PostCSS. You can disable the PostCSS process by specifying `false`.
|
|
188
|
+
- `configFilePath` (optional) ... Specifies the path of the directory containing the PostCSS configuration.
|
|
189
|
+
|
|
190
|
+
e.g.
|
|
191
|
+
|
|
192
|
+
```js
|
|
193
|
+
module.exports = {
|
|
194
|
+
// ...
|
|
195
|
+
settings: {
|
|
196
|
+
svelte: {
|
|
197
|
+
ignoreWarnings: [
|
|
198
|
+
"@typescript-eslint/no-unsafe-assignment",
|
|
199
|
+
"@typescript-eslint/no-unsafe-member-access",
|
|
200
|
+
],
|
|
201
|
+
compileOptions: {
|
|
202
|
+
postcss: {
|
|
203
|
+
configFilePath: "./path/to/my/postcss.config.js",
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
},
|
|
71
207
|
},
|
|
208
|
+
// ...
|
|
72
209
|
}
|
|
73
210
|
```
|
|
74
211
|
|
|
75
|
-
|
|
212
|
+
### Running ESLint from the command line
|
|
213
|
+
|
|
214
|
+
If you want to run `eslint` from the 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.
|
|
215
|
+
|
|
216
|
+
Examples:
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
eslint --ext .js,.svelte src
|
|
220
|
+
eslint "src/**/*.{js,svelte}"
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## :computer: Editor Integrations
|
|
224
|
+
|
|
225
|
+
### Visual Studio Code
|
|
226
|
+
|
|
227
|
+
Use the [dbaeumer.vscode-eslint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) extension that Microsoft provides officially.
|
|
228
|
+
|
|
229
|
+
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.
|
|
230
|
+
|
|
231
|
+
Example **.vscode/settings.json**:
|
|
232
|
+
|
|
233
|
+
```json
|
|
234
|
+
{
|
|
235
|
+
"eslint.validate": ["javascript", "javascriptreact", "svelte"]
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
<!--USAGE_GUIDE_END-->
|
|
240
|
+
<!--USAGE_SECTION_END-->
|
|
241
|
+
|
|
242
|
+
## :white_check_mark: Rules
|
|
243
|
+
|
|
244
|
+
<!--RULES_SECTION_START-->
|
|
245
|
+
|
|
246
|
+
The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) automatically fixes problems reported by rules which have a wrench :wrench: below.
|
|
247
|
+
The rules with the following star :star: are included in the configs.
|
|
248
|
+
|
|
249
|
+
<!--RULES_TABLE_START-->
|
|
250
|
+
|
|
251
|
+
## Possible Errors
|
|
252
|
+
|
|
253
|
+
These rules relate to possible syntax or logic errors in Svelte code:
|
|
254
|
+
|
|
255
|
+
| Rule ID | Description | |
|
|
256
|
+
|:--------|:------------|:---|
|
|
257
|
+
| [svelte/no-dupe-else-if-blocks](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-dupe-else-if-blocks/) | disallow duplicate conditions in `{#if}` / `{:else if}` chains | :star: |
|
|
258
|
+
| [svelte/no-dupe-style-properties](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-dupe-style-properties/) | disallow duplicate style properties | :star: |
|
|
259
|
+
| [svelte/no-dynamic-slot-name](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-dynamic-slot-name/) | disallow dynamic slot name | :star::wrench: |
|
|
260
|
+
| [svelte/no-not-function-handler](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-not-function-handler/) | disallow use of not function in event handler | :star: |
|
|
261
|
+
| [svelte/no-object-in-text-mustaches](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-object-in-text-mustaches/) | disallow objects in text mustache interpolation | :star: |
|
|
262
|
+
| [svelte/no-shorthand-style-property-overrides](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-shorthand-style-property-overrides/) | disallow shorthand style properties that override related longhand properties | :star: |
|
|
263
|
+
| [svelte/no-unknown-style-directive-property](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-unknown-style-directive-property/) | disallow unknown `style:property` | :star: |
|
|
264
|
+
| [svelte/valid-compile](https://ota-meshi.github.io/eslint-plugin-svelte/rules/valid-compile/) | disallow warnings when compiling. | :star: |
|
|
265
|
+
|
|
266
|
+
## Security Vulnerability
|
|
267
|
+
|
|
268
|
+
These rules relate to security vulnerabilities in Svelte code:
|
|
269
|
+
|
|
270
|
+
| Rule ID | Description | |
|
|
271
|
+
|:--------|:------------|:---|
|
|
272
|
+
| [svelte/no-at-html-tags](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-at-html-tags/) | disallow use of `{@html}` to prevent XSS attack | :star: |
|
|
273
|
+
| [svelte/no-target-blank](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-target-blank/) | disallow `target="_blank"` attribute without `rel="noopener noreferrer"` | |
|
|
274
|
+
|
|
275
|
+
## Best Practices
|
|
276
|
+
|
|
277
|
+
These rules relate to better ways of doing things to help you avoid problems:
|
|
278
|
+
|
|
279
|
+
| Rule ID | Description | |
|
|
280
|
+
|:--------|:------------|:---|
|
|
281
|
+
| [svelte/button-has-type](https://ota-meshi.github.io/eslint-plugin-svelte/rules/button-has-type/) | disallow usage of button without an explicit type attribute | |
|
|
282
|
+
| [svelte/no-at-debug-tags](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-at-debug-tags/) | disallow the use of `{@debug}` | :star: |
|
|
283
|
+
| [svelte/no-unused-svelte-ignore](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-unused-svelte-ignore/) | disallow unused svelte-ignore comments | :star: |
|
|
284
|
+
| [svelte/no-useless-mustaches](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-useless-mustaches/) | disallow unnecessary mustache interpolations | :wrench: |
|
|
285
|
+
| [svelte/require-optimized-style-attribute](https://ota-meshi.github.io/eslint-plugin-svelte/rules/require-optimized-style-attribute/) | require style attributes that can be optimized | |
|
|
286
|
+
|
|
287
|
+
## Stylistic Issues
|
|
288
|
+
|
|
289
|
+
These rules relate to style guidelines, and are therefore quite subjective:
|
|
290
|
+
|
|
291
|
+
| Rule ID | Description | |
|
|
292
|
+
|:--------|:------------|:---|
|
|
293
|
+
| [svelte/first-attribute-linebreak](https://ota-meshi.github.io/eslint-plugin-svelte/rules/first-attribute-linebreak/) | enforce the location of first attribute | :wrench: |
|
|
294
|
+
| [svelte/html-quotes](https://ota-meshi.github.io/eslint-plugin-svelte/rules/html-quotes/) | enforce quotes style of HTML attributes | :wrench: |
|
|
295
|
+
| [svelte/indent](https://ota-meshi.github.io/eslint-plugin-svelte/rules/indent/) | enforce consistent indentation | :wrench: |
|
|
296
|
+
| [svelte/max-attributes-per-line](https://ota-meshi.github.io/eslint-plugin-svelte/rules/max-attributes-per-line/) | enforce the maximum number of attributes per line | :wrench: |
|
|
297
|
+
| [svelte/mustache-spacing](https://ota-meshi.github.io/eslint-plugin-svelte/rules/mustache-spacing/) | enforce unified spacing in mustache | :wrench: |
|
|
298
|
+
| [svelte/prefer-class-directive](https://ota-meshi.github.io/eslint-plugin-svelte/rules/prefer-class-directive/) | require class directives instead of ternary expressions | :wrench: |
|
|
299
|
+
| [svelte/prefer-style-directive](https://ota-meshi.github.io/eslint-plugin-svelte/rules/prefer-style-directive/) | require style directives instead of style attribute | :wrench: |
|
|
300
|
+
| [svelte/shorthand-attribute](https://ota-meshi.github.io/eslint-plugin-svelte/rules/shorthand-attribute/) | enforce use of shorthand syntax in attribute | :wrench: |
|
|
301
|
+
| [svelte/shorthand-directive](https://ota-meshi.github.io/eslint-plugin-svelte/rules/shorthand-directive/) | enforce use of shorthand syntax in directives | :wrench: |
|
|
302
|
+
| [svelte/spaced-html-comment](https://ota-meshi.github.io/eslint-plugin-svelte/rules/spaced-html-comment/) | enforce consistent spacing after the `<!--` and before the `-->` in a HTML comment | :wrench: |
|
|
303
|
+
|
|
304
|
+
## Extension Rules
|
|
305
|
+
|
|
306
|
+
These rules extend the rules provided by ESLint itself to work well in Svelte:
|
|
307
|
+
|
|
308
|
+
| Rule ID | Description | |
|
|
309
|
+
|:--------|:------------|:---|
|
|
310
|
+
| [svelte/no-inner-declarations](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-inner-declarations/) | disallow variable or `function` declarations in nested blocks | :star: |
|
|
311
|
+
|
|
312
|
+
## System
|
|
313
|
+
|
|
314
|
+
These rules relate to this plugin works:
|
|
315
|
+
|
|
316
|
+
| Rule ID | Description | |
|
|
317
|
+
|:--------|:------------|:---|
|
|
318
|
+
| [svelte/comment-directive](https://ota-meshi.github.io/eslint-plugin-svelte/rules/comment-directive/) | support comment-directives in HTML template | :star: |
|
|
319
|
+
| [svelte/system](https://ota-meshi.github.io/eslint-plugin-svelte/rules/system/) | system rule for working this plugin | :star: |
|
|
320
|
+
|
|
321
|
+
<!--RULES_TABLE_END-->
|
|
322
|
+
<!--RULES_SECTION_END-->
|
|
323
|
+
|
|
324
|
+
<!--DOCS_IGNORE_START-->
|
|
325
|
+
|
|
326
|
+
## :beers: Contributing
|
|
327
|
+
|
|
328
|
+
Welcome contributing!
|
|
329
|
+
|
|
330
|
+
Please use GitHub's Issues/PRs.
|
|
331
|
+
|
|
332
|
+
### Development Tools
|
|
333
|
+
|
|
334
|
+
- `yarn test` runs tests.
|
|
335
|
+
- `yarn cover` runs tests and measures coverage.
|
|
336
|
+
- `yarn update` runs in order to update readme and recommended configuration.
|
|
337
|
+
|
|
338
|
+
### Test the Rule
|
|
339
|
+
|
|
340
|
+
Rule testing almost always uses fixtures.
|
|
341
|
+
For example, for an `indent` rule, the `.ts` file that runs the test is `tests/src/rules/indent.ts` and the fixture is in `tests/fixtures/rules/indent`.
|
|
342
|
+
The fixture directory has an `invalid` directory and a `valid` directory.
|
|
343
|
+
|
|
344
|
+
- The `invalid` directory contains test cases where the rule reports problems.
|
|
345
|
+
- The `valid` directory contains test cases where the rule does not report a problem.
|
|
346
|
+
|
|
347
|
+
The fixture input file should be named `*-input.svelte`. It is automatically collected and tested.
|
|
348
|
+
If your test requires configuration, you need to add a json file with the configuration.
|
|
349
|
+
|
|
350
|
+
- If you want to apply a configuration to `my-test-input.svelte`, add `my-test-config.json`.
|
|
351
|
+
- If you want to apply the same configuration to all the fixtures in that directory, add `_config.json`.
|
|
352
|
+
|
|
353
|
+
To verify the output of invalid test cases requires `*-errors.json`, and `*-output.svelte` (for auto-fix). However, you don't have to add them yourself. If they do not exist, they will be automatically generated when you run the test. In other words, delete them manually when you want to recreate them.
|
|
354
|
+
|
|
355
|
+
**Tips**:
|
|
356
|
+
|
|
357
|
+
If you want to test only one rule, run the following command (for `indent` rule):
|
|
358
|
+
|
|
359
|
+
```sh
|
|
360
|
+
yarn test -g indent
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
Take https://stackoverflow.com/questions/10832031/how-to-run-a-single-test-with-mocha as reference for details.
|
|
364
|
+
|
|
365
|
+
If you want to test only `my-test-input.svelte`, add `my-test-config.json` and save `{"only": true}`.
|
|
366
|
+
(Note that `{"only": true}` must be removed before making a pull request.)
|
|
367
|
+
|
|
368
|
+
### Working With Rules
|
|
369
|
+
|
|
370
|
+
This plugin uses [svelte-eslint-parser](https://github.com/ota-meshi/svelte-eslint-parser) for the parser. Check [here](https://ota-meshi.github.io/svelte-eslint-parser/) to find out about AST.
|
|
371
|
+
|
|
372
|
+
<!--DOCS_IGNORE_END-->
|
|
76
373
|
|
|
77
|
-
## License
|
|
374
|
+
## :lock: License
|
|
78
375
|
|
|
79
|
-
[
|
|
376
|
+
See the [LICENSE](LICENSE) file for license rights and limitations (MIT).
|
|
80
377
|
|
|
81
|
-
[
|
|
82
|
-
[
|
|
83
|
-
[mit]: http://opensource.org/licenses/MIT
|
|
84
|
-
[`eslint-plugin-svelte3`]: https://github.com/sveltejs/eslint-plugin-svelte3
|
|
378
|
+
[svelte]: https://svelte.dev/
|
|
379
|
+
[eslint]: https://eslint.org/
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = {
|
|
3
|
+
plugins: ["svelte"],
|
|
4
|
+
overrides: [
|
|
5
|
+
{
|
|
6
|
+
files: ["*.svelte"],
|
|
7
|
+
parser: require.resolve("svelte-eslint-parser"),
|
|
8
|
+
rules: {
|
|
9
|
+
"no-inner-declarations": "off",
|
|
10
|
+
"svelte/comment-directive": "error",
|
|
11
|
+
"svelte/system": "error",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
],
|
|
15
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
extends: string[];
|
|
3
|
+
rules: {
|
|
4
|
+
"svelte/comment-directive": string;
|
|
5
|
+
"svelte/no-at-debug-tags": string;
|
|
6
|
+
"svelte/no-at-html-tags": string;
|
|
7
|
+
"svelte/no-dupe-else-if-blocks": string;
|
|
8
|
+
"svelte/no-dupe-style-properties": string;
|
|
9
|
+
"svelte/no-dynamic-slot-name": string;
|
|
10
|
+
"svelte/no-inner-declarations": string;
|
|
11
|
+
"svelte/no-not-function-handler": string;
|
|
12
|
+
"svelte/no-object-in-text-mustaches": string;
|
|
13
|
+
"svelte/no-shorthand-style-property-overrides": string;
|
|
14
|
+
"svelte/no-unknown-style-directive-property": string;
|
|
15
|
+
"svelte/no-unused-svelte-ignore": string;
|
|
16
|
+
"svelte/system": string;
|
|
17
|
+
"svelte/valid-compile": string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export = _default;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const path_1 = __importDefault(require("path"));
|
|
6
|
+
const base = require.resolve("./base");
|
|
7
|
+
const baseExtend = path_1.default.extname(`${base}`) === ".ts" ? "plugin:svelte/base" : base;
|
|
8
|
+
module.exports = {
|
|
9
|
+
extends: [baseExtend],
|
|
10
|
+
rules: {
|
|
11
|
+
"svelte/comment-directive": "error",
|
|
12
|
+
"svelte/no-at-debug-tags": "warn",
|
|
13
|
+
"svelte/no-at-html-tags": "error",
|
|
14
|
+
"svelte/no-dupe-else-if-blocks": "error",
|
|
15
|
+
"svelte/no-dupe-style-properties": "error",
|
|
16
|
+
"svelte/no-dynamic-slot-name": "error",
|
|
17
|
+
"svelte/no-inner-declarations": "error",
|
|
18
|
+
"svelte/no-not-function-handler": "error",
|
|
19
|
+
"svelte/no-object-in-text-mustaches": "error",
|
|
20
|
+
"svelte/no-shorthand-style-property-overrides": "error",
|
|
21
|
+
"svelte/no-unknown-style-directive-property": "error",
|
|
22
|
+
"svelte/no-unused-svelte-ignore": "error",
|
|
23
|
+
"svelte/system": "error",
|
|
24
|
+
"svelte/valid-compile": "error",
|
|
25
|
+
},
|
|
26
|
+
};
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { RuleModule } from "./types";
|
|
2
|
+
import * as processor from "./processor";
|
|
3
|
+
declare const _default: {
|
|
4
|
+
configs: {
|
|
5
|
+
base: {
|
|
6
|
+
plugins: string[];
|
|
7
|
+
overrides: {
|
|
8
|
+
files: string[];
|
|
9
|
+
parser: string;
|
|
10
|
+
rules: {
|
|
11
|
+
"no-inner-declarations": string;
|
|
12
|
+
"svelte/comment-directive": string;
|
|
13
|
+
"svelte/system": string;
|
|
14
|
+
};
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
17
|
+
recommended: {
|
|
18
|
+
extends: string[];
|
|
19
|
+
rules: {
|
|
20
|
+
"svelte/comment-directive": string;
|
|
21
|
+
"svelte/no-at-debug-tags": string;
|
|
22
|
+
"svelte/no-at-html-tags": string;
|
|
23
|
+
"svelte/no-dupe-else-if-blocks": string;
|
|
24
|
+
"svelte/no-dupe-style-properties": string;
|
|
25
|
+
"svelte/no-dynamic-slot-name": string;
|
|
26
|
+
"svelte/no-inner-declarations": string;
|
|
27
|
+
"svelte/no-not-function-handler": string;
|
|
28
|
+
"svelte/no-object-in-text-mustaches": string;
|
|
29
|
+
"svelte/no-shorthand-style-property-overrides": string;
|
|
30
|
+
"svelte/no-unknown-style-directive-property": string;
|
|
31
|
+
"svelte/no-unused-svelte-ignore": string;
|
|
32
|
+
"svelte/system": string;
|
|
33
|
+
"svelte/valid-compile": string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
rules: {
|
|
38
|
+
[key: string]: RuleModule;
|
|
39
|
+
};
|
|
40
|
+
processors: {
|
|
41
|
+
".svelte": typeof processor;
|
|
42
|
+
svelte: typeof processor;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
export = _default;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
const rules_1 = require("./utils/rules");
|
|
29
|
+
const base_1 = __importDefault(require("./configs/base"));
|
|
30
|
+
const recommended_1 = __importDefault(require("./configs/recommended"));
|
|
31
|
+
const processor = __importStar(require("./processor"));
|
|
32
|
+
const configs = {
|
|
33
|
+
base: base_1.default,
|
|
34
|
+
recommended: recommended_1.default,
|
|
35
|
+
};
|
|
36
|
+
const rules = rules_1.rules.reduce((obj, r) => {
|
|
37
|
+
obj[r.meta.docs.ruleName] = r;
|
|
38
|
+
return obj;
|
|
39
|
+
}, {});
|
|
40
|
+
module.exports = {
|
|
41
|
+
configs,
|
|
42
|
+
rules,
|
|
43
|
+
processors: {
|
|
44
|
+
".svelte": processor,
|
|
45
|
+
svelte: processor,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Linter } from "eslint";
|
|
2
|
+
export declare function preprocess(code: string, filename: string): string[];
|
|
3
|
+
export declare function postprocess([messages]: Linter.LintMessage[][], filename: string): Linter.LintMessage[];
|
|
4
|
+
export declare const supportsAutofix = true;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.supportsAutofix = exports.postprocess = exports.preprocess = void 0;
|
|
4
|
+
const shared_1 = require("../shared");
|
|
5
|
+
function preprocess(code, filename) {
|
|
6
|
+
if (filename) {
|
|
7
|
+
(0, shared_1.beginShared)(filename);
|
|
8
|
+
}
|
|
9
|
+
return [code];
|
|
10
|
+
}
|
|
11
|
+
exports.preprocess = preprocess;
|
|
12
|
+
function postprocess([messages], filename) {
|
|
13
|
+
const shared = (0, shared_1.terminateShared)(filename);
|
|
14
|
+
if (shared) {
|
|
15
|
+
return filter(messages, shared);
|
|
16
|
+
}
|
|
17
|
+
return messages;
|
|
18
|
+
}
|
|
19
|
+
exports.postprocess = postprocess;
|
|
20
|
+
exports.supportsAutofix = true;
|
|
21
|
+
function filter(messages, shared) {
|
|
22
|
+
if (shared.commentDirectives.length === 0) {
|
|
23
|
+
return messages;
|
|
24
|
+
}
|
|
25
|
+
let filteredMessages = messages;
|
|
26
|
+
for (const cd of shared.commentDirectives) {
|
|
27
|
+
filteredMessages = cd.filterMessages(filteredMessages);
|
|
28
|
+
}
|
|
29
|
+
return filteredMessages;
|
|
30
|
+
}
|