Skip to content

Commit 3ecafc5

Browse files
authored
Merge branch 'ota-meshi:main' into reactive-destructuring
2 parents a99e8d6 + 119e4af commit 3ecafc5

File tree

527 files changed

+16959
-17171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

527 files changed

+16959
-17171
lines changed

.github/workflows/GHPages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
- name: Upload artifact
3838
uses: actions/upload-pages-artifact@v1
3939
with:
40-
path: ./build
40+
path: ./build/eslint-plugin-svelte
4141
- name: Deploy to GitHub Pages
4242
id: deployment
4343
uses: actions/deploy-pages@v1

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,9 @@ Example **.vscode/settings.json**:
244244

245245
<!--RULES_SECTION_START-->
246246

247-
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.
248-
The rules with the following star :star: are included in the configs.
247+
:wrench: Indicates that the rule is fixable, and using `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the reported problems.
248+
:bulb: Indicates that some problems reported by the rule are manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
249+
:star: Indicates that the rule is included in the `plugin:svelte/recommended` config.
249250

250251
<!--RULES_TABLE_START-->
251252

@@ -281,11 +282,13 @@ These rules relate to better ways of doing things to help you avoid problems:
281282
|:--------|:------------|:---|
282283
| [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 | |
283284
| [svelte/no-at-debug-tags](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-at-debug-tags/) | disallow the use of `{@debug}` | :star: |
284-
| [svelte/no-reactive-literals](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-reactive-literals/) | Don't assign literal values in reactive statements | |
285+
| [svelte/no-reactive-functions](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-reactive-functions/) | It's not necessary to define functions in reactive statements | :bulb: |
286+
| [svelte/no-reactive-literals](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-reactive-literals/) | Don't assign literal values in reactive statements | :bulb: |
285287
| [svelte/no-unused-svelte-ignore](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-unused-svelte-ignore/) | disallow unused svelte-ignore comments | :star: |
286288
| [svelte/no-useless-mustaches](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-useless-mustaches/) | disallow unnecessary mustache interpolations | :wrench: |
287289
| [svelte/prefer-reactive-destructuring](https://ota-meshi.github.io/eslint-plugin-svelte/rules/prefer-reactive-destructuring/) | Prefer destructuring from objects in reactive statements | |
288290
| [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 | |
291+
| [svelte/require-stores-init](https://ota-meshi.github.io/eslint-plugin-svelte/rules/require-stores-init/) | require initial value in store | |
289292

290293
## Stylistic Issues
291294

@@ -296,14 +299,17 @@ These rules relate to style guidelines, and are therefore quite subjective:
296299
| [svelte/first-attribute-linebreak](https://ota-meshi.github.io/eslint-plugin-svelte/rules/first-attribute-linebreak/) | enforce the location of first attribute | :wrench: |
297300
| [svelte/html-closing-bracket-spacing](https://ota-meshi.github.io/eslint-plugin-svelte/rules/html-closing-bracket-spacing/) | require or disallow a space before tag's closing brackets | :wrench: |
298301
| [svelte/html-quotes](https://ota-meshi.github.io/eslint-plugin-svelte/rules/html-quotes/) | enforce quotes style of HTML attributes | :wrench: |
302+
| [svelte/html-self-closing](https://ota-meshi.github.io/eslint-plugin-svelte/rules/html-self-closing/) | enforce self-closing style | :wrench: |
299303
| [svelte/indent](https://ota-meshi.github.io/eslint-plugin-svelte/rules/indent/) | enforce consistent indentation | :wrench: |
300304
| [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: |
301305
| [svelte/mustache-spacing](https://ota-meshi.github.io/eslint-plugin-svelte/rules/mustache-spacing/) | enforce unified spacing in mustache | :wrench: |
306+
| [svelte/no-extra-reactive-curlies](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-extra-reactive-curlies/) | disallow wrapping single reactive statements in curly braces | :bulb: |
302307
| [svelte/no-spaces-around-equal-signs-in-attribute](https://ota-meshi.github.io/eslint-plugin-svelte/rules/no-spaces-around-equal-signs-in-attribute/) | disallow spaces around equal signs in attribute | :wrench: |
303308
| [svelte/prefer-class-directive](https://ota-meshi.github.io/eslint-plugin-svelte/rules/prefer-class-directive/) | require class directives instead of ternary expressions | :wrench: |
304309
| [svelte/prefer-style-directive](https://ota-meshi.github.io/eslint-plugin-svelte/rules/prefer-style-directive/) | require style directives instead of style attribute | :wrench: |
305310
| [svelte/shorthand-attribute](https://ota-meshi.github.io/eslint-plugin-svelte/rules/shorthand-attribute/) | enforce use of shorthand syntax in attribute | :wrench: |
306311
| [svelte/shorthand-directive](https://ota-meshi.github.io/eslint-plugin-svelte/rules/shorthand-directive/) | enforce use of shorthand syntax in directives | :wrench: |
312+
| [svelte/sort-attributes](https://ota-meshi.github.io/eslint-plugin-svelte/rules/sort-attributes/) | enforce order of attributes | :wrench: |
307313
| [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: |
308314

309315
## Extension Rules

docs-svelte-kit/build-system/build.mts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import esbuild from "esbuild"
22
import path from "path"
33
import fs from "fs"
4+
import { fileURLToPath } from "url"
45
// const babelCore = require("@babel/core")
56
// const t = require("@babel/types")
67

78
const dirname = path.dirname(
8-
new URL(
9+
fileURLToPath(
910
// @ts-expect-error -- Cannot change `module` option
1011
import.meta.url,
11-
).pathname,
12+
),
1213
)
1314

1415
build(

docs-svelte-kit/src/lib/components/ESLintCodeBlock.svelte

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
let code = ""
1313
export let rules = {}
1414
export let fix = false
15+
export let language = "html"
1516
let time = ""
16-
let options = {
17-
filename: "example.svelte",
17+
$: options = {
18+
filename: language === "html" ? "example.svelte" : "example.js",
1819
preprocess,
1920
postprocess,
2021
}
@@ -43,7 +44,7 @@
4344
{linter}
4445
bind:code
4546
config={{
46-
parser: "svelte-eslint-parser",
47+
parser: language === "html" ? "svelte-eslint-parser" : undefined,
4748
parserOptions: {
4849
ecmaVersion: 2020,
4950
sourceType: "module",
@@ -54,6 +55,7 @@
5455
es2021: true,
5556
},
5657
}}
58+
{language}
5759
{options}
5860
on:result={onLintedResult}
5961
showDiff={showDiff && fix}

docs-svelte-kit/src/lib/eslint/ESLintEditor.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
export let options = {}
1212
export let fix = true
1313
export let showDiff = true
14+
export let language = "html"
1415
1516
let fixedValue = code
1617
let leftMarkers = []
@@ -221,7 +222,7 @@
221222
bind:this={editor}
222223
bind:code
223224
bind:rightCode={fixedValue}
224-
language="html"
225+
{language}
225226
diffEditor={fix && showDiff}
226227
markers={leftMarkers}
227228
{rightMarkers}

docs-svelte-kit/tools/highlight.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const EXTENSION_MAPPINGS: Record<string, string | undefined> = {
2626
styl: "stylus",
2727
kt: "kotlin",
2828
rs: "rust",
29+
jsonc: "json5",
2930
}
3031

3132
export default (str: string, lang: string): string => {

docs/rules.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ sidebarDepth: 0
44

55
# Available Rules
66

7-
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.
8-
The rules with the following star :star: are included in the `plugin:svelte/recommended` config.
7+
:wrench: Indicates that the rule is fixable, and using `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the reported problems.
8+
:bulb: Indicates that some problems reported by the rule are manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
9+
:star: Indicates that the rule is included in the `plugin:svelte/recommended` config.
910

1011
<!-- This file is automatically generated in tools/update-docs-rules-index.js, do not change! -->
1112

@@ -41,11 +42,13 @@ These rules relate to better ways of doing things to help you avoid problems:
4142
|:--------|:------------|:---|
4243
| [svelte/button-has-type](./rules/button-has-type.md) | disallow usage of button without an explicit type attribute | |
4344
| [svelte/no-at-debug-tags](./rules/no-at-debug-tags.md) | disallow the use of `{@debug}` | :star: |
44-
| [svelte/no-reactive-literals](./rules/no-reactive-literals.md) | Don't assign literal values in reactive statements | |
45+
| [svelte/no-reactive-functions](./rules/no-reactive-functions.md) | It's not necessary to define functions in reactive statements | :bulb: |
46+
| [svelte/no-reactive-literals](./rules/no-reactive-literals.md) | Don't assign literal values in reactive statements | :bulb: |
4547
| [svelte/no-unused-svelte-ignore](./rules/no-unused-svelte-ignore.md) | disallow unused svelte-ignore comments | :star: |
4648
| [svelte/no-useless-mustaches](./rules/no-useless-mustaches.md) | disallow unnecessary mustache interpolations | :wrench: |
4749
| [svelte/prefer-reactive-destructuring](./rules/prefer-reactive-destructuring.md) | Prefer destructuring from objects in reactive statements | |
4850
| [svelte/require-optimized-style-attribute](./rules/require-optimized-style-attribute.md) | require style attributes that can be optimized | |
51+
| [svelte/require-stores-init](./rules/require-stores-init.md) | require initial value in store | |
4952

5053
## Stylistic Issues
5154

@@ -56,14 +59,17 @@ These rules relate to style guidelines, and are therefore quite subjective:
5659
| [svelte/first-attribute-linebreak](./rules/first-attribute-linebreak.md) | enforce the location of first attribute | :wrench: |
5760
| [svelte/html-closing-bracket-spacing](./rules/html-closing-bracket-spacing.md) | require or disallow a space before tag's closing brackets | :wrench: |
5861
| [svelte/html-quotes](./rules/html-quotes.md) | enforce quotes style of HTML attributes | :wrench: |
62+
| [svelte/html-self-closing](./rules/html-self-closing.md) | enforce self-closing style | :wrench: |
5963
| [svelte/indent](./rules/indent.md) | enforce consistent indentation | :wrench: |
6064
| [svelte/max-attributes-per-line](./rules/max-attributes-per-line.md) | enforce the maximum number of attributes per line | :wrench: |
6165
| [svelte/mustache-spacing](./rules/mustache-spacing.md) | enforce unified spacing in mustache | :wrench: |
66+
| [svelte/no-extra-reactive-curlies](./rules/no-extra-reactive-curlies.md) | disallow wrapping single reactive statements in curly braces | :bulb: |
6267
| [svelte/no-spaces-around-equal-signs-in-attribute](./rules/no-spaces-around-equal-signs-in-attribute.md) | disallow spaces around equal signs in attribute | :wrench: |
6368
| [svelte/prefer-class-directive](./rules/prefer-class-directive.md) | require class directives instead of ternary expressions | :wrench: |
6469
| [svelte/prefer-style-directive](./rules/prefer-style-directive.md) | require style directives instead of style attribute | :wrench: |
6570
| [svelte/shorthand-attribute](./rules/shorthand-attribute.md) | enforce use of shorthand syntax in attribute | :wrench: |
6671
| [svelte/shorthand-directive](./rules/shorthand-directive.md) | enforce use of shorthand syntax in directives | :wrench: |
72+
| [svelte/sort-attributes](./rules/sort-attributes.md) | enforce order of attributes | :wrench: |
6773
| [svelte/spaced-html-comment](./rules/spaced-html-comment.md) | enforce consistent spacing after the `<!--` and before the `-->` in a HTML comment | :wrench: |
6874

6975
## Extension Rules

docs/rules/html-self-closing.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
pageClass: "rule-details"
3+
sidebarDepth: 0
4+
title: "svelte/html-self-closing"
5+
description: "enforce self-closing style"
6+
---
7+
8+
# svelte/html-self-closing
9+
10+
> enforce self-closing style
11+
12+
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> **_This rule has not been released yet._** </badge>
13+
- :wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
14+
15+
## :book: Rule Details
16+
17+
You can choose either two styles for elements without content
18+
19+
- always: `<div />`
20+
- never: `<div></div>`
21+
22+
<ESLintCodeBlock fix>
23+
24+
<!-- prettier-ignore-start -->
25+
<!--eslint-skip-->
26+
27+
```svelte
28+
<script>
29+
/* eslint svelte/html-self-closing: "error" */
30+
</script>
31+
32+
<!-- ✓ GOOD -->
33+
<div />
34+
<p>Hello</p>
35+
<div><div /></div>
36+
<img />
37+
<svelte:head />
38+
39+
<!-- ✗ BAD -->
40+
<div></div>
41+
<p> </p>
42+
<div><div></div></div>
43+
<img>
44+
<svelte:head></svelte:head>
45+
```
46+
47+
<!-- prettier-ignore-end -->
48+
49+
</ESLintCodeBlock>
50+
51+
## :wrench: Options
52+
53+
```jsonc
54+
{
55+
"svelte/html-self-closing": [
56+
"error",
57+
{
58+
"void": "always", // or "always" or "ignore"
59+
"normal": "always", // or "never" or "ignore"
60+
"component": "always", // or "never" or "ignore"
61+
"svelte": "always" // or "never" or "ignore"
62+
}
63+
]
64+
}
65+
```
66+
67+
- `void` (`"always"` by default)... Style of HTML void elements
68+
- `component` (`"always"` by default)... Style of svelte components
69+
- `svelte` (`"always"` by default)... Style of svelte special elements (`<svelte:head>`, `<svelte:self>`)
70+
- `normal` (`"always"` by default)... Style of other elements
71+
72+
Every option can be set to
73+
- "always" (`<div />`)
74+
- "never" (`<div></div>`)
75+
- "ignore" (either `<div />` or `<div></div>`)
76+
77+
## :mag: Implementation
78+
79+
- [Rule source](https://github.com/ota-meshi/eslint-plugin-svelte/blob/main/src/rules/html-self-closing.ts)
80+
- [Test source](https://github.com/ota-meshi/eslint-plugin-svelte/blob/main/tests/src/rules/html-self-closing.ts)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
pageClass: "rule-details"
3+
sidebarDepth: 0
4+
title: "svelte/no-extra-reactive-curlies"
5+
description: "disallow wrapping single reactive statements in curly braces"
6+
since: "v2.4.0"
7+
---
8+
9+
# svelte/no-extra-reactive-curlies
10+
11+
> disallow wrapping single reactive statements in curly braces
12+
13+
- :bulb: Some problems reported by this rule are manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
14+
15+
## :book: Rule Details
16+
17+
This rule reports if curly brackets (`{` and `}`) are used unnecessarily around a reactive statement body containing only a single expression.
18+
19+
<ESLintCodeBlock>
20+
21+
<!--eslint-skip-->
22+
23+
```svelte
24+
<script>
25+
/* eslint svelte/no-extra-reactive-curlies: "error" */
26+
27+
/* ✓ GOOD */
28+
$: foo = "red"
29+
30+
/* ✗ BAD */
31+
$: {
32+
foo = "red"
33+
}
34+
</script>
35+
```
36+
37+
</ESLintCodeBlock>
38+
39+
## :wrench: Options
40+
41+
Nothing.
42+
43+
## :heart: Compatibility
44+
45+
This rule was taken from [@tivac/eslint-plugin-svelte].
46+
This rule is compatible with `@tivac/svelte/reactive-curlies` rule.
47+
48+
[@tivac/eslint-plugin-svelte]: https://github.com/tivac/eslint-plugin-svelte/
49+
50+
## :rocket: Version
51+
52+
This rule was introduced in eslint-plugin-svelte v2.4.0
53+
54+
## :mag: Implementation
55+
56+
- [Rule source](https://github.com/ota-meshi/eslint-plugin-svelte/blob/main/src/rules/no-extra-reactive-curlies.ts)
57+
- [Test source](https://github.com/ota-meshi/eslint-plugin-svelte/blob/main/tests/src/rules/no-extra-reactive-curlies.ts)

docs/rules/no-reactive-functions.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
pageClass: "rule-details"
3+
sidebarDepth: 0
4+
title: "svelte/no-reactive-functions"
5+
description: "It's not necessary to define functions in reactive statements"
6+
---
7+
8+
# svelte/no-reactive-functions
9+
10+
> It's not necessary to define functions in reactive statements
11+
12+
- :exclamation: <badge text="This rule has not been released yet." vertical="middle" type="error"> **_This rule has not been released yet._** </badge>
13+
- :bulb: Some problems reported by this rule are manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
14+
15+
## :book: Rule Details
16+
17+
This rule reports whenever a function is defined in a reactive statement. This isn't necessary, as each time the function is executed it'll already have access to the latest values necessary. Redefining the function in the reactive statement is just a waste of CPU cycles.
18+
19+
<ESLintCodeBlock>
20+
21+
<!--eslint-skip-->
22+
23+
```svelte
24+
<script>
25+
/* eslint svelte/no-reactive-functions: "error" */
26+
27+
/* ✓ GOOD */
28+
const arrowFn = () => { /* ... */ }
29+
const func = function() { /* ... */ }
30+
31+
/* ✗ BAD */
32+
$: arrowFn = () => { /* ... */ }
33+
$: func = function() { /* ... */ }
34+
</script>
35+
```
36+
37+
</ESLintCodeBlock>
38+
39+
## :wrench: Options
40+
41+
Nothing
42+
43+
## :heart: Compatibility
44+
45+
This rule was taken from [@tivac/eslint-plugin-svelte].
46+
This rule is compatible with `@tivac/svelte/reactive-functions` rule.
47+
48+
[@tivac/eslint-plugin-svelte]: https://github.com/tivac/eslint-plugin-svelte/
49+
## :mag: Implementation
50+
51+
- [Rule source](https://github.com/ota-meshi/eslint-plugin-svelte/blob/main/src/rules/no-reactive-functions.ts)
52+
- [Test source](https://github.com/ota-meshi/eslint-plugin-svelte/blob/main/tests/src/rules/no-reactive-functions.ts)

0 commit comments

Comments
 (0)