eslint-plugin-svelte 1.1.2 → 2.0.0

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.
Files changed (138) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +315 -51
  3. package/lib/configs/base.d.ts +13 -0
  4. package/lib/configs/base.js +15 -0
  5. package/lib/configs/recommended.d.ts +20 -0
  6. package/lib/configs/recommended.js +26 -0
  7. package/lib/index.d.ts +45 -0
  8. package/lib/index.js +47 -0
  9. package/lib/processor/index.d.ts +4 -0
  10. package/lib/processor/index.js +30 -0
  11. package/lib/rules/button-has-type.d.ts +2 -0
  12. package/lib/rules/button-has-type.js +96 -0
  13. package/lib/rules/comment-directive.d.ts +2 -0
  14. package/lib/rules/comment-directive.js +177 -0
  15. package/lib/rules/first-attribute-linebreak.d.ts +2 -0
  16. package/lib/rules/first-attribute-linebreak.js +68 -0
  17. package/lib/rules/html-quotes.d.ts +2 -0
  18. package/lib/rules/html-quotes.js +170 -0
  19. package/lib/rules/indent-helpers/ast.d.ts +6 -0
  20. package/lib/rules/indent-helpers/ast.js +15 -0
  21. package/lib/rules/indent-helpers/commons.d.ts +27 -0
  22. package/lib/rules/indent-helpers/commons.js +56 -0
  23. package/lib/rules/indent-helpers/es.d.ts +5 -0
  24. package/lib/rules/indent-helpers/es.js +740 -0
  25. package/lib/rules/indent-helpers/index.d.ts +3 -0
  26. package/lib/rules/indent-helpers/index.js +223 -0
  27. package/lib/rules/indent-helpers/offset-context.d.ts +57 -0
  28. package/lib/rules/indent-helpers/offset-context.js +196 -0
  29. package/lib/rules/indent-helpers/svelte.d.ts +5 -0
  30. package/lib/rules/indent-helpers/svelte.js +380 -0
  31. package/lib/rules/indent-helpers/ts.d.ts +5 -0
  32. package/lib/rules/indent-helpers/ts.js +735 -0
  33. package/lib/rules/indent.d.ts +2 -0
  34. package/lib/rules/indent.js +47 -0
  35. package/lib/rules/max-attributes-per-line.d.ts +2 -0
  36. package/lib/rules/max-attributes-per-line.js +101 -0
  37. package/lib/rules/mustache-spacing.d.ts +2 -0
  38. package/lib/rules/mustache-spacing.js +255 -0
  39. package/lib/rules/no-at-debug-tags.d.ts +2 -0
  40. package/lib/rules/no-at-debug-tags.js +28 -0
  41. package/lib/rules/no-at-html-tags.d.ts +2 -0
  42. package/lib/rules/no-at-html-tags.js +27 -0
  43. package/lib/rules/no-dupe-else-if-blocks.d.ts +2 -0
  44. package/lib/rules/no-dupe-else-if-blocks.js +100 -0
  45. package/lib/rules/no-dupe-style-properties.d.ts +2 -0
  46. package/lib/rules/no-dupe-style-properties.js +89 -0
  47. package/lib/rules/no-dynamic-slot-name.d.ts +2 -0
  48. package/lib/rules/no-dynamic-slot-name.js +76 -0
  49. package/lib/rules/no-inner-declarations.d.ts +2 -0
  50. package/lib/rules/no-inner-declarations.js +36 -0
  51. package/lib/rules/no-not-function-handler.d.ts +2 -0
  52. package/lib/rules/no-not-function-handler.js +91 -0
  53. package/lib/rules/no-object-in-text-mustaches.d.ts +2 -0
  54. package/lib/rules/no-object-in-text-mustaches.js +50 -0
  55. package/lib/rules/no-shorthand-style-property-overrides.d.ts +2 -0
  56. package/lib/rules/no-shorthand-style-property-overrides.js +97 -0
  57. package/lib/rules/no-target-blank.d.ts +2 -0
  58. package/lib/rules/no-target-blank.js +84 -0
  59. package/lib/rules/no-unknown-style-directive-property.d.ts +2 -0
  60. package/lib/rules/no-unknown-style-directive-property.js +65 -0
  61. package/lib/rules/no-unused-svelte-ignore.d.ts +2 -0
  62. package/lib/rules/no-unused-svelte-ignore.js +52 -0
  63. package/lib/rules/no-useless-mustaches.d.ts +2 -0
  64. package/lib/rules/no-useless-mustaches.js +126 -0
  65. package/lib/rules/prefer-class-directive.d.ts +2 -0
  66. package/lib/rules/prefer-class-directive.js +246 -0
  67. package/lib/rules/prefer-style-directive.d.ts +2 -0
  68. package/lib/rules/prefer-style-directive.js +153 -0
  69. package/lib/rules/require-optimized-style-attribute.d.ts +2 -0
  70. package/lib/rules/require-optimized-style-attribute.js +80 -0
  71. package/lib/rules/shorthand-attribute.d.ts +2 -0
  72. package/lib/rules/shorthand-attribute.js +83 -0
  73. package/lib/rules/shorthand-directive.d.ts +2 -0
  74. package/lib/rules/shorthand-directive.js +103 -0
  75. package/lib/rules/spaced-html-comment.d.ts +2 -0
  76. package/lib/rules/spaced-html-comment.js +84 -0
  77. package/lib/rules/system.d.ts +2 -0
  78. package/lib/rules/system.js +71 -0
  79. package/lib/rules/valid-compile.d.ts +2 -0
  80. package/lib/rules/valid-compile.js +55 -0
  81. package/lib/shared/comment-directives.d.ts +21 -0
  82. package/lib/shared/comment-directives.js +150 -0
  83. package/lib/shared/index.d.ts +8 -0
  84. package/lib/shared/index.js +31 -0
  85. package/lib/shared/svelte-compile-warns/extract-leading-comments.d.ts +4 -0
  86. package/lib/shared/svelte-compile-warns/extract-leading-comments.js +34 -0
  87. package/lib/shared/svelte-compile-warns/ignore-comment.d.ts +13 -0
  88. package/lib/shared/svelte-compile-warns/ignore-comment.js +75 -0
  89. package/lib/shared/svelte-compile-warns/index.d.ts +24 -0
  90. package/lib/shared/svelte-compile-warns/index.js +456 -0
  91. package/lib/shared/svelte-compile-warns/transform/babel.d.ts +5 -0
  92. package/lib/shared/svelte-compile-warns/transform/babel.js +48 -0
  93. package/lib/shared/svelte-compile-warns/transform/less.d.ts +4 -0
  94. package/lib/shared/svelte-compile-warns/transform/less.js +45 -0
  95. package/lib/shared/svelte-compile-warns/transform/load-module.d.ts +3 -0
  96. package/lib/shared/svelte-compile-warns/transform/load-module.js +74 -0
  97. package/lib/shared/svelte-compile-warns/transform/postcss.d.ts +4 -0
  98. package/lib/shared/svelte-compile-warns/transform/postcss.js +43 -0
  99. package/lib/shared/svelte-compile-warns/transform/sass.d.ts +4 -0
  100. package/lib/shared/svelte-compile-warns/transform/sass.js +39 -0
  101. package/lib/shared/svelte-compile-warns/transform/stylus.d.ts +4 -0
  102. package/lib/shared/svelte-compile-warns/transform/stylus.js +44 -0
  103. package/lib/shared/svelte-compile-warns/transform/types.d.ts +6 -0
  104. package/lib/shared/svelte-compile-warns/transform/types.js +2 -0
  105. package/lib/shared/svelte-compile-warns/transform/typescript.d.ts +5 -0
  106. package/lib/shared/svelte-compile-warns/transform/typescript.js +44 -0
  107. package/lib/types-for-node.d.ts +394 -0
  108. package/lib/types-for-node.js +2 -0
  109. package/lib/types.d.ts +180 -0
  110. package/lib/types.js +2 -0
  111. package/lib/utils/ast-utils.d.ts +43 -0
  112. package/lib/utils/ast-utils.js +269 -0
  113. package/lib/utils/css-utils/index.d.ts +3 -0
  114. package/lib/utils/css-utils/index.js +19 -0
  115. package/lib/utils/css-utils/resource.d.ts +1 -0
  116. package/lib/utils/css-utils/resource.js +219 -0
  117. package/lib/utils/css-utils/style-attribute.d.ts +43 -0
  118. package/lib/utils/css-utils/style-attribute.js +259 -0
  119. package/lib/utils/css-utils/template-safe-parser.d.ts +5 -0
  120. package/lib/utils/css-utils/template-safe-parser.js +13 -0
  121. package/lib/utils/css-utils/template-tokenize.d.ts +5 -0
  122. package/lib/utils/css-utils/template-tokenize.js +44 -0
  123. package/lib/utils/css-utils/utils.d.ts +3 -0
  124. package/lib/utils/css-utils/utils.js +16 -0
  125. package/lib/utils/eslint-core.d.ts +13 -0
  126. package/lib/utils/eslint-core.js +57 -0
  127. package/lib/utils/index.d.ts +2 -0
  128. package/lib/utils/index.js +10 -0
  129. package/lib/utils/lines-and-columns.d.ts +12 -0
  130. package/lib/utils/lines-and-columns.js +54 -0
  131. package/lib/utils/regexp.d.ts +2 -0
  132. package/lib/utils/regexp.js +23 -0
  133. package/lib/utils/rules.d.ts +2 -0
  134. package/lib/utils/rules.js +64 -0
  135. package/package.json +133 -11
  136. package/CHANGELOG.md +0 -7
  137. package/index.js +0 -10
  138. package/processor-options.js +0 -44
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 JounQin
3
+ Copyright (c) 2021 Yosuke Ota
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,84 +1,348 @@
1
- # eslint-plugin-svelte
1
+ # Introduction
2
2
 
3
- [![npm](https://img.shields.io/npm/v/eslint-plugin-svelte.svg)](https://www.npmjs.com/package/eslint-plugin-svelte)
4
- [![GitHub Release](https://img.shields.io/github/release/JounQin/eslint-plugin-svelte)](https://github.com/JounQin/eslint-plugin-svelte/releases)
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
- [![David Peer](https://img.shields.io/david/peer/JounQin/eslint-plugin-svelte.svg)](https://david-dm.org/JounQin/eslint-plugin-svelte?type=peer)
7
- [![David](https://img.shields.io/david/JounQin/eslint-plugin-svelte.svg)](https://david-dm.org/JounQin/eslint-plugin-svelte)
8
- [![David Dev](https://img.shields.io/david/dev/JounQin/eslint-plugin-svelte.svg)](https://david-dm.org/JounQin/eslint-plugin-svelte?type=dev)
7
+ [![NPM license](https://img.shields.io/npm/l/eslint-plugin-svelte.svg)](https://www.npmjs.com/package/eslint-plugin-svelte)
8
+ [![NPM version](https://img.shields.io/npm/v/eslint-plugin-svelte.svg)](https://www.npmjs.com/package/eslint-plugin-svelte)
9
+ [![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/eslint-plugin-svelte&maxAge=3600)](http://www.npmtrends.com/eslint-plugin-svelte)
10
+ [![NPM downloads](https://img.shields.io/npm/dw/eslint-plugin-svelte.svg)](http://www.npmtrends.com/eslint-plugin-svelte)
11
+ [![NPM downloads](https://img.shields.io/npm/dm/eslint-plugin-svelte.svg)](http://www.npmtrends.com/eslint-plugin-svelte)
12
+ [![NPM downloads](https://img.shields.io/npm/dy/eslint-plugin-svelte.svg)](http://www.npmtrends.com/eslint-plugin-svelte)
13
+ [![NPM downloads](https://img.shields.io/npm/dt/eslint-plugin-svelte.svg)](http://www.npmtrends.com/eslint-plugin-svelte)
14
+ [![Build Status](https://github.com/ota-meshi/eslint-plugin-svelte/workflows/CI/badge.svg?branch=main)](https://github.com/ota-meshi/eslint-plugin-svelte/actions?query=workflow%3ACI)
9
15
 
10
- [![Conventional Commits](https://img.shields.io/badge/conventional%20commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
11
- [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
12
- [![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
16
+ ## :name_badge: What is this plugin?
13
17
 
14
- - [What](#what)
15
- - [Why](#why)
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
- ## What
21
+ ### ❓ Why?
22
22
 
23
- Just an alias to [`eslint-plugin-svelte3`][]
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
- ## Why
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
- Personally I'd prefer a consistent eslint plugin for all versions of a framework like [`eslint-plugin-vue`](https://github.com/vuejs/eslint-plugin-vue), but the original author of this plugin has [different opinion](https://github.com/sveltejs/eslint-plugin-svelte3/issues/90#issuecomment-783570346). So I decide to just post this alias package for constant and cleaner usage for myself.
27
+ ### Attention
28
28
 
29
- ## How
29
+ The [svelte-eslint-parser] and the `eslint-plugin-svelte` can not be used with the [eslint-plugin-svelte3].
30
30
 
31
- ### Version strategy
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
- We will start from `v1.1.1` which represents `v3.1.1` of [`eslint-plugin-svelte3`][] , and follow all of its versions then. What means maybe following (notice: the version of `eslint-plugin-svelte*` are all just assumptions):
34
+ <!--DOCS_IGNORE_START-->
34
35
 
35
- 1. patch: `eslint-plugin-svelte3@3.1.2` -> `eslint-plugin-svelte@1.1.2`
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
- If we are changing some internal codes, the version would be `x.y.z-minor.patch`.
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
- ### Usage
40
+ ## :book: Documentation
45
41
 
46
- It should be just like [`eslint-plugin-svelte3`][] itself, but renaming all `svelte*` to simple `svelte`, for instance:
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
- parserOptions: {
51
- ecmaVersion: 2019,
52
- sourceType: 'module',
53
- },
54
- env: {
55
- es6: true,
56
- browser: true,
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
- plugins: ['svelte'],
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: ['*.svelte'],
62
- processor: 'svelte/svelte',
117
+ files: ["*.svelte"],
118
+ parser: "svelte-eslint-parser",
63
119
  },
120
+ // ...
64
121
  ],
65
- rules: {
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
- settings: {
69
- 'svelte/typescript': require('typescript'), // pass the TypeScript package to the Svelte plugin
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
+ },
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
+ },
70
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
+ // ...
209
+ }
210
+ ```
211
+
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"]
72
236
  }
73
237
  ```
74
238
 
75
- Don't forget to read original documentation first.
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 and measures coverage.
335
+ - `yarn update` runs in order to update readme and recommended configuration.
336
+
337
+ ### Working With Rules
338
+
339
+ 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.
340
+
341
+ <!--DOCS_IGNORE_END-->
76
342
 
77
- ## License
343
+ ## :lock: License
78
344
 
79
- [MIT][] © [JounQin][]@[1stG.me][]
345
+ See the [LICENSE](LICENSE) file for license rights and limitations (MIT).
80
346
 
81
- [1stg.me]: https://www.1stg.me
82
- [jounqin]: https://GitHub.com/JounQin
83
- [mit]: http://opensource.org/licenses/MIT
84
- [`eslint-plugin-svelte3`]: https://github.com/sveltejs/eslint-plugin-svelte3
347
+ [svelte]: https://svelte.dev/
348
+ [eslint]: https://eslint.org/
@@ -0,0 +1,13 @@
1
+ declare const _default: {
2
+ plugins: string[];
3
+ overrides: {
4
+ files: string[];
5
+ parser: string;
6
+ rules: {
7
+ "no-inner-declarations": string;
8
+ "svelte/comment-directive": string;
9
+ "svelte/system": string;
10
+ };
11
+ }[];
12
+ };
13
+ export = _default;
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: import("../types").RuleModule;
2
+ export default _default;