Skip to content

Commit

Permalink
feat: (experimental) partial support for Svelte v5 (#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi authored Nov 21, 2023
1 parent 371bb20 commit 1097107
Show file tree
Hide file tree
Showing 59 changed files with 306 additions and 39 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-cats-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-svelte": minor
---

feat: (experimental) partial support for Svelte v5
8 changes: 8 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"mode": "pre",
"tag": "next",
"initialVersions": {
"eslint-plugin-svelte": "2.35.0"
},
"changesets": []
}
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/tests/fixtures/rules/valid-compile/valid/ts
/tests/fixtures/rules/prefer-style-directive
/tests/fixtures/rules/@typescript-eslint
/tests/fixtures/rules/valid-compile/valid/svelte3-options-custom-element-input.svelte
/.svelte-kit
/svelte.config-dist.js
/build
Expand Down
27 changes: 25 additions & 2 deletions .github/workflows/NodeCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ jobs:
pnpm run update
pnpm run build
test:
name: 'Test for ESLint ${{ matrix.eslint }} on ${{ matrix.node }} OS: ${{matrix.os}}'
name: 'Test for ESLint ${{ matrix.eslint }} on Node.js: ${{ matrix.node }} OS: ${{matrix.os}}'
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
eslint: [7, 8]
node: [16, 17, 18, 20]
node: [20]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -58,6 +58,29 @@ jobs:
run: pnpm install
- name: Test
run: pnpm run test
test-for-svelte-v4:
name: 'Test for Svelte v4 on Node.js: ${{ matrix.node }} OS: ${{matrix.os}}'
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
node: [16, 17, 18, 20]
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
- name: Setup Node.js ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Install svelte@4
run: |+
pnpm install -D svelte@4
rm -rf node_modules
- name: Install Packages
run: pnpm install
- name: Test
run: pnpm run test
test-for-svelte-v3:
name: Test for Svelte v3
runs-on: ${{ matrix.os }}
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ It provides many unique check rules using the AST generated by [svelte-eslint-pa

### ❗ Attention

#### Cannot be used with eslint-plugin-svelte3

The [svelte-eslint-parser] and the `eslint-plugin-svelte` can not be used with the [eslint-plugin-svelte3].

[svelte-eslint-parser]: https://github.com/sveltejs/svelte-eslint-parser
[eslint-plugin-svelte3]: https://github.com/sveltejs/eslint-plugin-svelte3

#### Experimental support for Svelte v5

We are working on support for Svelte v5, but it is still an experimental feature. Please note that rules and features related to Svelte v5 may be changed or removed in minor versions without notice.

<!--DOCS_IGNORE_START-->

## Migration Guide
Expand Down
6 changes: 6 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@ It provides many unique check rules using the AST generated by [svelte-eslint-pa

### ❗ Attention

#### Cannot be used with eslint-plugin-svelte3

The [svelte-eslint-parser] and the `eslint-plugin-svelte` can not be used with the [eslint-plugin-svelte3].

[svelte-eslint-parser]: https://github.com/sveltejs/svelte-eslint-parser
[eslint-plugin-svelte3]: https://github.com/sveltejs/eslint-plugin-svelte3

#### Experimental support for Svelte v5

We are working on support for Svelte v5, but it is still an experimental feature. Please note that rules and features related to Svelte v5 may be changed or removed in minor versions without notice.

## :book: Usage

See [User Guide](./user-guide.md).
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
},
"peerDependencies": {
"eslint": "^7.0.0 || ^8.0.0-0",
"svelte": "^3.37.0 || ^4.0.0"
"svelte": "^3.37.0 || ^4.0.0 || ^5.0.0-next.8"
},
"peerDependenciesMeta": {
"svelte": {
Expand All @@ -77,7 +77,7 @@
"postcss-safe-parser": "^6.0.0",
"postcss-selector-parser": "^6.0.11",
"semver": "^7.5.3",
"svelte-eslint-parser": ">=0.33.0 <1.0.0"
"svelte-eslint-parser": ">=0.34.0-next.2 <1.0.0"
},
"devDependencies": {
"@1stg/browserslist-config": "^1.2.3",
Expand Down Expand Up @@ -164,7 +164,7 @@
"stylelint": "^15.0.0",
"stylelint-config-standard": "^34.0.0",
"stylus": "^0.62.0",
"svelte": "^4.0.0",
"svelte": "^5.0.0-next.8",
"svelte-adapter-ghpages": "0.1.0",
"svelte-i18n": "^4.0.0",
"tslib": "^2.5.0",
Expand Down
1 change: 1 addition & 0 deletions src/rules/indent-helpers/commons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export function isBeginningOfElement(node: AST.SvelteText): boolean {
node.parent.type === 'SvelteElseBlock' ||
node.parent.type === 'SvelteIfBlock' ||
node.parent.type === 'SvelteKeyBlock' ||
node.parent.type === 'SvelteSnippetBlock' ||
node.parent.type === 'SvelteStyleElement'
) {
return node.parent.children[0] === node;
Expand Down
8 changes: 7 additions & 1 deletion src/rules/valid-compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ export default createRule('valid-compile', {
}
const ignoreWarnings = Boolean(context.options[0]?.ignoreWarnings);

const ignores = ['missing-declaration', 'dynamic-slot-name'];
const ignores = [
'missing-declaration',
// Svelte v4
'dynamic-slot-name',
// Svelte v5
'invalid-slot-name'
];

/**
* report
Expand Down
4 changes: 4 additions & 0 deletions src/types-for-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export type ASTNodeListener = {
SvelteMustacheTag?: (node: AST.SvelteMustacheTag & ASTNodeWithParent) => void;
SvelteDebugTag?: (node: AST.SvelteDebugTag & ASTNodeWithParent) => void;
SvelteConstTag?: (node: AST.SvelteConstTag & ASTNodeWithParent) => void;
SvelteRenderTag?: (node: AST.SvelteRenderTag & ASTNodeWithParent) => void;
SvelteIfBlock?: (node: AST.SvelteIfBlock & ASTNodeWithParent) => void;
SvelteElseBlock?: (node: AST.SvelteElseBlock & ASTNodeWithParent) => void;
SvelteEachBlock?: (node: AST.SvelteEachBlock & ASTNodeWithParent) => void;
Expand All @@ -229,6 +230,7 @@ export type ASTNodeListener = {
SvelteAwaitThenBlock?: (node: AST.SvelteAwaitThenBlock & ASTNodeWithParent) => void;
SvelteAwaitCatchBlock?: (node: AST.SvelteAwaitCatchBlock & ASTNodeWithParent) => void;
SvelteKeyBlock?: (node: AST.SvelteKeyBlock & ASTNodeWithParent) => void;
SvelteSnippetBlock?: (node: AST.SvelteSnippetBlock & ASTNodeWithParent) => void;
SvelteAttribute?: (node: AST.SvelteAttribute & ASTNodeWithParent) => void;
SvelteShorthandAttribute?: (node: AST.SvelteShorthandAttribute & ASTNodeWithParent) => void;
SvelteSpreadAttribute?: (node: AST.SvelteSpreadAttribute & ASTNodeWithParent) => void;
Expand Down Expand Up @@ -439,6 +441,7 @@ export type SvelteNodeListener = {
SvelteMustacheTag?: (node: AST.SvelteMustacheTag & ASTNodeWithParent) => void;
SvelteDebugTag?: (node: AST.SvelteDebugTag & ASTNodeWithParent) => void;
SvelteConstTag?: (node: AST.SvelteConstTag & ASTNodeWithParent) => void;
SvelteRenderTag?: (node: AST.SvelteRenderTag & ASTNodeWithParent) => void;
SvelteIfBlock?: (node: AST.SvelteIfBlock & ASTNodeWithParent) => void;
SvelteElseBlock?: (node: AST.SvelteElseBlock & ASTNodeWithParent) => void;
SvelteEachBlock?: (node: AST.SvelteEachBlock & ASTNodeWithParent) => void;
Expand All @@ -447,6 +450,7 @@ export type SvelteNodeListener = {
SvelteAwaitThenBlock?: (node: AST.SvelteAwaitThenBlock & ASTNodeWithParent) => void;
SvelteAwaitCatchBlock?: (node: AST.SvelteAwaitCatchBlock & ASTNodeWithParent) => void;
SvelteKeyBlock?: (node: AST.SvelteKeyBlock & ASTNodeWithParent) => void;
SvelteSnippetBlock?: (node: AST.SvelteSnippetBlock & ASTNodeWithParent) => void;
SvelteAttribute?: (node: AST.SvelteAttribute & ASTNodeWithParent) => void;
SvelteShorthandAttribute?: (node: AST.SvelteShorthandAttribute & ASTNodeWithParent) => void;
SvelteSpreadAttribute?: (node: AST.SvelteSpreadAttribute & ASTNodeWithParent) => void;
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures/rules/indent/invalid/await01-input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@ name
/await
}
</div>

<!--tests/fixtures/rules/indent/invalid/await01-input.svelte-->
2 changes: 2 additions & 0 deletions tests/fixtures/rules/indent/invalid/await01-output.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,5 @@
/await
}
</div>

<!--tests/fixtures/rules/indent/invalid/await01-input.svelte-->
4 changes: 4 additions & 0 deletions tests/fixtures/rules/indent/invalid/await01-requirements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"FIXME": "It seems to return the wrong location in Svelte v5.",
"svelte": "^4 || ^3"
}
4 changes: 4 additions & 0 deletions tests/fixtures/rules/indent/invalid/each01-requirements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"FIXME": "It seems to return the wrong location in Svelte v5.",
"svelte": "^4 || ^3"
}
4 changes: 4 additions & 0 deletions tests/fixtures/rules/indent/invalid/if01-requirements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"FIXME": "It seems to return the wrong location in Svelte v5.",
"svelte": "^4 || ^3"
}
4 changes: 4 additions & 0 deletions tests/fixtures/rules/indent/invalid/key01-requirements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"FIXME": "It seems to return the wrong location in Svelte v5.",
"svelte": "^4 || ^3"
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@
{#await expression}...{:then}...{:catch}...{/await}

{#key expression}...{/key}

<!--tests/fixtures/rules/mustache-spacing/invalid/always/test01-input.svelte-->
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@
{ #await expression }...{ :then}...{ :catch}...{ /await }

{ #key expression }...{ /key }

<!--tests/fixtures/rules/mustache-spacing/invalid/always/test01-input.svelte-->
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@

{ #key expression }...{ /key }
</div>

<!--tests/fixtures/rules/mustache-spacing/invalid/test01-input.svelte-->
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@

{#key expression}...{/key}
</div>

<!--tests/fixtures/rules/mustache-spacing/invalid/test01-input.svelte-->
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"FIXME": "It seems to return the wrong location in Svelte v5.",
"svelte": "^4 || ^3"
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
- message: svelte-ignore comment is used, but not warned
line: 3
column: 19
suggestions: null
- message: svelte-ignore comment is used, but not warned
line: 5
line: 4
column: 19
suggestions: null
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<script>
let foo;
// svelte-ignore unused-export-let
export let used;
// svelte-ignore module-script-reactive-declaration
$: reactive = foo;
// svelte-ignore state-rune-not-mutated
let mutable = $state(42);
// svelte-ignore state-rune-not-mutated
let immutable = $state(42);
export function update(a) {
immutable = a;
}
</script>

{used}
{mutable}{immutable}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"svelte": ">=5.0.0-0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- message: svelte-ignore comment is used, but not warned
line: 3
column: 19
suggestions: null
- message: svelte-ignore comment is used, but not warned
line: 5
column: 19
suggestions: null
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script>
let foo;
// svelte-ignore unused-export-let
export let used;
// svelte-ignore module-script-reactive-declaration
$: reactive = foo;
</script>

{used}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"svelte": "^3.0.0 || ^4.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"svelte": "^3.0.0 || ^4.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"svelte": "^3.0.0 || ^4.0.0"
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<script context="module">
let foo;
</script>

<script>
// svelte-ignore unused-export-let
export let unused;
// svelte-ignore module-script-reactive-declaration
$: reactive = foo;
// svelte-ignore state-rune-not-mutated
let immutable = $state(42);
</script>

{immutable}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"svelte": ">=5.0.0-0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script context="module">
let foo;
</script>

<script>
// svelte-ignore unused-export-let
export let unused;
// svelte-ignore module-script-reactive-declaration
$: reactive = foo;
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"svelte": "^3.0.0 || ^4.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"FIXME": "It seems that unused selectors are not checked yet in Svelte v5.",
"svelte": "^4 || ^3"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"FIXME": "It seems that unused selectors are not checked yet in Svelte v5.",
"svelte": "^4 || ^3"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"FIXME": "It seems that unused selectors are not checked yet in Svelte v5.",
"svelte": "^4 || ^3"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"FIXME": "It seems that unused selectors are not checked yet in Svelte v5.",
"svelte": "^4 || ^3"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"FIXME": "It seems that unused selectors are not checked yet in Svelte v5.",
"svelte": "^4 || ^3"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"FIXME": "It seems that unused selectors are not checked yet in Svelte v5.",
"svelte": "^4 || ^3"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<script lang="ts">
// svelte-ignore unused-export-let
export let something;
<script>
let mutable = $state(42);
// svelte-ignore state-rune-not-mutated
let immutable = $state(42);
export function update(a) {
mutable = a;
}
</script>

{mutable}{immutable}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"svelte": ">=5.0.0-0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<script lang="ts">
// svelte-ignore unused-export-let
export let something;
</script>
Loading

0 comments on commit 1097107

Please sign in to comment.