@@ -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 : {
@@ -58,20 +76,7 @@ export default createRule('valid-prop-names-in-kit-pages', {
58
76
}
59
77
60
78
// export let { xxx, yyy } = zzz
61
- if ( node . id . type !== 'ObjectPattern' ) return ;
62
- for ( const p of node . id . properties ) {
63
- if (
64
- p . type === 'Property' &&
65
- p . value . type === 'Identifier' &&
66
- ! EXPECTED_PROP_NAMES . includes ( p . value . name )
67
- ) {
68
- context . report ( {
69
- node : p . value ,
70
- loc : p . value . loc ,
71
- messageId : 'unexpected'
72
- } ) ;
73
- }
74
- }
79
+ checkProp ( node , context ) ;
75
80
} ,
76
81
77
82
// Svelte5
@@ -86,20 +91,7 @@ export default createRule('valid-prop-names-in-kit-pages', {
86
91
return ;
87
92
}
88
93
89
- if ( node . id . type !== 'ObjectPattern' ) return ;
90
- for ( const p of node . id . properties ) {
91
- if (
92
- p . type === 'Property' &&
93
- p . value . type === 'Identifier' &&
94
- ! EXPECTED_PROP_NAMES . includes ( p . value . name )
95
- ) {
96
- context . report ( {
97
- node : p . value ,
98
- loc : p . value . loc ,
99
- messageId : 'unexpected'
100
- } ) ;
101
- }
102
- }
94
+ checkProp ( node , context ) ;
103
95
}
104
96
} ;
105
97
}
0 commit comments