@@ -21,7 +21,7 @@ function findDeclarationCallee(node: TSESTree.Expression) {
21
21
* Determines if a declaration should be skipped in the const preference analysis.
22
22
* Specifically checks for Svelte's state management utilities ($props, $derived).
23
23
*/
24
- function shouldSkipDeclaration ( declaration : TSESTree . Expression | null ) {
24
+ function shouldSkipDeclaration ( declaration : TSESTree . Expression | null , excludedRunes : string [ ] ) {
25
25
if ( ! declaration ) {
26
26
return false ;
27
27
}
@@ -31,15 +31,15 @@ function shouldSkipDeclaration(declaration: TSESTree.Expression | null) {
31
31
return false ;
32
32
}
33
33
34
- if ( callee . type === 'Identifier' && [ '$props' , '$state' , '$derived' ] . includes ( callee . name ) ) {
34
+ if ( callee . type === 'Identifier' && excludedRunes . includes ( callee . name ) ) {
35
35
return true ;
36
36
}
37
37
38
38
if ( callee . type !== 'MemberExpression' || callee . object . type !== 'Identifier' ) {
39
39
return false ;
40
40
}
41
41
42
- if ( callee . object . name === '$state' || callee . object . name === '$derived' ) {
42
+ if ( excludedRunes . includes ( callee . object . name ) ) {
43
43
return true ;
44
44
}
45
45
@@ -54,16 +54,32 @@ export default createRule('prefer-const', {
54
54
category : 'Best Practices' ,
55
55
recommended : false ,
56
56
extensionRule : 'prefer-const'
57
- }
57
+ } ,
58
+ schema : [
59
+ {
60
+ type : 'object' ,
61
+ properties : {
62
+ excludedRunes : {
63
+ type : 'array' ,
64
+ items : {
65
+ type : 'string'
66
+ }
67
+ }
68
+ }
69
+ }
70
+ ]
58
71
} ,
59
72
create ( context ) {
73
+ const config = context . options [ 0 ] ?? { } ;
74
+ const excludedRunes = config . excludedRunes ?? [ '$props' , '$derived' ] ;
75
+
60
76
return defineWrapperListener ( coreRule , context , {
61
77
createListenerProxy ( coreListener ) {
62
78
return {
63
79
...coreListener ,
64
80
VariableDeclaration ( node ) {
65
81
for ( const decl of node . declarations ) {
66
- if ( shouldSkipDeclaration ( decl . init ) ) {
82
+ if ( shouldSkipDeclaration ( decl . init , excludedRunes ) ) {
67
83
return ;
68
84
}
69
85
}
0 commit comments