@@ -110,13 +110,13 @@ const schema: JSONSchema4[] = [
110110/**
111111 * The default options for the rule.
112112 */
113- const defaultOptions : RawOptions = [
113+ const defaultOptions = [
114114 {
115115 ignoreClasses : false ,
116116 ignoreImmediateMutation : true ,
117117 ignoreNonConstDeclarations : false ,
118118 } ,
119- ] ;
119+ ] satisfies RawOptions ;
120120
121121/**
122122 * The possible error messages.
@@ -227,10 +227,8 @@ function checkAssignmentExpression(
227227) : RuleResult < keyof typeof errorMessages , RawOptions > {
228228 const options = upgradeRawOverridableOptions ( rawOptions [ 0 ] ) ;
229229 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 ) ,
234232 ) ;
235233
236234 if ( optionsToUse === null ) {
@@ -306,10 +304,8 @@ function checkUnaryExpression(
306304) : RuleResult < keyof typeof errorMessages , RawOptions > {
307305 const options = upgradeRawOverridableOptions ( rawOptions [ 0 ] ) ;
308306 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 ) ,
313309 ) ;
314310
315311 if ( optionsToUse === null ) {
@@ -384,10 +380,8 @@ function checkUpdateExpression(
384380) : RuleResult < keyof typeof errorMessages , RawOptions > {
385381 const options = upgradeRawOverridableOptions ( rawOptions [ 0 ] ) ;
386382 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 ) ,
391385 ) ;
392386
393387 if ( optionsToUse === null ) {
@@ -533,6 +527,20 @@ function isInChainCallAndFollowsNew(
533527 return false ;
534528}
535529
530+ /**
531+ * Add the default options to the given options.
532+ */
533+ function getOptionsWithDefaults ( options : Readonly < Options > | null ) : Options {
534+ if ( options === null ) {
535+ return defaultOptions [ 0 ] ;
536+ }
537+
538+ return {
539+ ...defaultOptions [ 0 ] ,
540+ ...options ,
541+ } ;
542+ }
543+
536544/**
537545 * Check if the given node violates this rule.
538546 */
@@ -543,10 +551,8 @@ function checkCallExpression(
543551) : RuleResult < keyof typeof errorMessages , RawOptions > {
544552 const options = upgradeRawOverridableOptions ( rawOptions [ 0 ] ) ;
545553 const rootNode = findRootIdentifier ( node . callee ) ?? node . callee ;
546- const optionsToUse = getCoreOptions < CoreOptions , Options > (
547- rootNode ,
548- context ,
549- options ,
554+ const optionsToUse = getOptionsWithDefaults (
555+ getCoreOptions < CoreOptions , Options > ( rootNode , context , options ) ,
550556 ) ;
551557
552558 if ( optionsToUse === null ) {
0 commit comments