Skip to content

Commit 534ad78

Browse files
authored
feat(sort-attributes): support {@Attach} (#1221)
1 parent 0265218 commit 534ad78

File tree

9 files changed

+61
-6
lines changed

9 files changed

+61
-6
lines changed

.changeset/dry-facts-eat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-svelte': minor
3+
---
4+
5+
feat(sort-attributes): support `{@attach}`

docs-svelte-kit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"sass": "^1.81.0",
5757
"source-map-js": "^1.2.1",
5858
"stylus": "^0.64.0",
59-
"svelte": "^5.2.10",
59+
"svelte": "^5.30.1",
6060
"svelte-adapter-ghpages": "0.2.2",
6161
"twoslash-eslint": "^0.3.0",
6262
"twoslash-protocol": "^0.3.0",

packages/eslint-plugin-svelte/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"postcss-load-config": "^3.1.4",
6565
"postcss-safe-parser": "^7.0.0",
6666
"semver": "^7.6.3",
67-
"svelte-eslint-parser": "^1.1.1"
67+
"svelte-eslint-parser": "^1.2.0"
6868
},
6969
"devDependencies": {
7070
"@babel/core": "^7.26.0",
@@ -95,7 +95,7 @@
9595
"sass": "^1.81.0",
9696
"source-map-js": "^1.2.1",
9797
"stylus": "^0.64.0",
98-
"svelte": "^5.2.9",
98+
"svelte": "^5.30.1",
9999
"svelte-i18n": "^4.0.1",
100100
"tsx": "^4.19.2",
101101
"type-coverage": "^2.29.7",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// IMPORTANT!
22
// This file has been automatically generated,
33
// in order to update its content execute "pnpm run update"
4-
export const name = 'eslint-plugin-svelte' as const;
5-
export const version = '3.6.0' as const;
4+
export const name = 'eslint-plugin-svelte';
5+
export const version = '3.6.0';

packages/eslint-plugin-svelte/src/utils/ast-utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,8 @@ export function getAttributeKeyText(
462462
| SvAST.SvelteStyleDirective
463463
| SvAST.SvelteDirective
464464
| SvAST.SvelteSpecialDirective
465-
| SvAST.SvelteGenericsDirective,
465+
| SvAST.SvelteGenericsDirective
466+
| SvAST.SvelteAttachTag,
466467
context: RuleContext
467468
): string {
468469
switch (node.type) {
@@ -480,6 +481,8 @@ export function getAttributeKeyText(
480481
node.key.modifiers.length ? `|${node.key.modifiers.join('|')}` : ''
481482
}`;
482483
}
484+
case 'SvelteAttachTag':
485+
return '@attach';
483486
default:
484487
throw new Error(
485488
`Unknown node type: ${
@@ -556,6 +559,7 @@ export function findClassesInAttribute(
556559
| SvAST.SvelteStyleDirective
557560
| SvAST.SvelteSpecialDirective
558561
| SvAST.SvelteGenericsDirective
562+
| SvAST.SvelteAttachTag
559563
): string[] {
560564
if (attribute.type === 'SvelteAttribute' && attribute.key.name === 'class') {
561565
return attribute.value.flatMap((value) =>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- message: Attribute '@attach' should go before 'foo'.
2+
line: 14
3+
column: 10
4+
suggestions: null
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script lang="ts">
2+
import type { Attachment } from 'svelte/attachments';
3+
4+
5+
const myAttachment: Attachment = (element) => {
6+
console.log(element.nodeName); // 'DIV'
7+
8+
return () => {
9+
console.log('cleaning up');
10+
};
11+
};
12+
</script>
13+
14+
<div foo {@attach myAttachment}>...</div>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script lang="ts">
2+
import type { Attachment } from 'svelte/attachments';
3+
4+
5+
const myAttachment: Attachment = (element) => {
6+
console.log(element.nodeName); // 'DIV'
7+
8+
return () => {
9+
console.log('cleaning up');
10+
};
11+
};
12+
</script>
13+
14+
<div {@attach myAttachment} foo>...</div>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script lang="ts">
2+
import type { Attachment } from 'svelte/attachments';
3+
4+
5+
const myAttachment: Attachment = (element) => {
6+
console.log(element.nodeName); // 'DIV'
7+
8+
return () => {
9+
console.log('cleaning up');
10+
};
11+
};
12+
</script>
13+
14+
<div {@attach myAttachment}>...</div>

0 commit comments

Comments
 (0)