@@ -2,9 +2,27 @@ import type { AST } from 'svelte-eslint-parser';
2
2
import type { TSESTree } from '@typescript-eslint/types' ;
3
3
import { createRule } from '../utils/index.js' ;
4
4
import { isKitPageComponent } from '../utils/svelte-kit.js' ;
5
+ import type { RuleContext } from '../types.js' ;
5
6
6
7
const EXPECTED_PROP_NAMES = [ 'data' , 'errors' , 'form' , 'snapshot' ] ;
7
8
9
+ function checkProp ( node : TSESTree . VariableDeclarator , context : RuleContext ) {
10
+ if ( node . id . type !== 'ObjectPattern' ) return ;
11
+ for ( const p of node . id . properties ) {
12
+ if (
13
+ p . type === 'Property' &&
14
+ p . value . type === 'Identifier' &&
15
+ ! EXPECTED_PROP_NAMES . includes ( p . value . name )
16
+ ) {
17
+ context . report ( {
18
+ node : p . value ,
19
+ loc : p . value . loc ,
20
+ messageId : 'unexpected'
21
+ } ) ;
22
+ }
23
+ }
24
+ }
25
+
8
26
export default createRule ( 'valid-prop-names-in-kit-pages' , {
9
27
meta : {
10
28
docs : {
@@ -39,6 +57,7 @@ export default createRule('valid-prop-names-in-kit-pages', {
39
57
isScript = false ;
40
58
} ,
41
59
60
+ // Svelte3,4
42
61
'ExportNamedDeclaration > VariableDeclaration > VariableDeclarator' : (
43
62
node : TSESTree . VariableDeclarator
44
63
) => {
@@ -57,20 +76,22 @@ export default createRule('valid-prop-names-in-kit-pages', {
57
76
}
58
77
59
78
// export let { xxx, yyy } = zzz
60
- if ( node . id . type !== 'ObjectPattern' ) return ;
61
- for ( const p of node . id . properties ) {
62
- if (
63
- p . type === 'Property' &&
64
- p . value . type === 'Identifier' &&
65
- ! EXPECTED_PROP_NAMES . includes ( p . value . name )
66
- ) {
67
- context . report ( {
68
- node : p . value ,
69
- loc : p . value . loc ,
70
- messageId : 'unexpected '
71
- } ) ;
72
- }
79
+ checkProp ( node , context ) ;
80
+ } ,
81
+
82
+ // Svelte5
83
+ // let { foo, bar } = $props();
84
+ 'VariableDeclaration > VariableDeclarator' : ( node : TSESTree . VariableDeclarator ) => {
85
+ if ( ! isScript ) return ;
86
+ if (
87
+ node . init ?. type !== 'CallExpression' ||
88
+ node . init . callee ?. type !== 'Identifier' ||
89
+ node . init . callee ?. name !== '$props '
90
+ ) {
91
+ return ;
73
92
}
93
+
94
+ checkProp ( node , context ) ;
74
95
}
75
96
} ;
76
97
}
0 commit comments