@@ -110,13 +110,13 @@ const schema: JSONSchema4[] = [
110
110
/**
111
111
* The default options for the rule.
112
112
*/
113
- const defaultOptions : RawOptions = [
113
+ const defaultOptions = [
114
114
{
115
115
ignoreClasses : false ,
116
116
ignoreImmediateMutation : true ,
117
117
ignoreNonConstDeclarations : false ,
118
118
} ,
119
- ] ;
119
+ ] satisfies RawOptions ;
120
120
121
121
/**
122
122
* The possible error messages.
@@ -227,10 +227,8 @@ function checkAssignmentExpression(
227
227
) : RuleResult < keyof typeof errorMessages , RawOptions > {
228
228
const options = upgradeRawOverridableOptions ( rawOptions [ 0 ] ) ;
229
229
const rootNode = findRootIdentifier ( node . left ) ?? node . left ;
230
- const optionsToUse = getCoreOptions < CoreOptions , Options > (
231
- rootNode ,
232
- context ,
233
- options ,
230
+ const optionsToUse = getOptionsWithDefaults (
231
+ getCoreOptions < CoreOptions , Options > ( rootNode , context , options ) ,
234
232
) ;
235
233
236
234
if ( optionsToUse === null ) {
@@ -306,10 +304,8 @@ function checkUnaryExpression(
306
304
) : RuleResult < keyof typeof errorMessages , RawOptions > {
307
305
const options = upgradeRawOverridableOptions ( rawOptions [ 0 ] ) ;
308
306
const rootNode = findRootIdentifier ( node . argument ) ?? node . argument ;
309
- const optionsToUse = getCoreOptions < CoreOptions , Options > (
310
- rootNode ,
311
- context ,
312
- options ,
307
+ const optionsToUse = getOptionsWithDefaults (
308
+ getCoreOptions < CoreOptions , Options > ( rootNode , context , options ) ,
313
309
) ;
314
310
315
311
if ( optionsToUse === null ) {
@@ -384,10 +380,8 @@ function checkUpdateExpression(
384
380
) : RuleResult < keyof typeof errorMessages , RawOptions > {
385
381
const options = upgradeRawOverridableOptions ( rawOptions [ 0 ] ) ;
386
382
const rootNode = findRootIdentifier ( node . argument ) ?? node . argument ;
387
- const optionsToUse = getCoreOptions < CoreOptions , Options > (
388
- rootNode ,
389
- context ,
390
- options ,
383
+ const optionsToUse = getOptionsWithDefaults (
384
+ getCoreOptions < CoreOptions , Options > ( rootNode , context , options ) ,
391
385
) ;
392
386
393
387
if ( optionsToUse === null ) {
@@ -533,6 +527,22 @@ function isInChainCallAndFollowsNew(
533
527
return false ;
534
528
}
535
529
530
+ /**
531
+ * Add the default options to the given options.
532
+ */
533
+ function getOptionsWithDefaults (
534
+ options : Readonly < Options > | null ,
535
+ ) : Options | null {
536
+ if ( options === null ) {
537
+ return null ;
538
+ }
539
+
540
+ return {
541
+ ...defaultOptions [ 0 ] ,
542
+ ...options ,
543
+ } ;
544
+ }
545
+
536
546
/**
537
547
* Check if the given node violates this rule.
538
548
*/
@@ -543,10 +553,8 @@ function checkCallExpression(
543
553
) : RuleResult < keyof typeof errorMessages , RawOptions > {
544
554
const options = upgradeRawOverridableOptions ( rawOptions [ 0 ] ) ;
545
555
const rootNode = findRootIdentifier ( node . callee ) ?? node . callee ;
546
- const optionsToUse = getCoreOptions < CoreOptions , Options > (
547
- rootNode ,
548
- context ,
549
- options ,
556
+ const optionsToUse = getOptionsWithDefaults (
557
+ getCoreOptions < CoreOptions , Options > ( rootNode , context , options ) ,
550
558
) ;
551
559
552
560
if ( optionsToUse === null ) {
0 commit comments