@@ -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,22 @@ function isInChainCallAndFollowsNew(
533527 return false ;
534528}
535529
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+
536546/**
537547 * Check if the given node violates this rule.
538548 */
@@ -543,10 +553,8 @@ function checkCallExpression(
543553) : RuleResult < keyof typeof errorMessages , RawOptions > {
544554 const options = upgradeRawOverridableOptions ( rawOptions [ 0 ] ) ;
545555 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 ) ,
550558 ) ;
551559
552560 if ( optionsToUse === null ) {
0 commit comments