@@ -44,11 +44,13 @@ export enum RuleEnforcementComparator {
44
44
type FixerConfigRaw = {
45
45
pattern : string ;
46
46
replace : string ;
47
+ message ?: string ;
47
48
} ;
48
49
49
50
type FixerConfig = {
50
51
pattern : RegExp ;
51
52
replace : string ;
53
+ message ?: string ;
52
54
} ;
53
55
54
56
type SuggestionsConfig = FixerConfig [ ] ;
@@ -188,6 +190,7 @@ const errorMessages = {
188
190
Exactly : 'This type is declare to have an immutability of exactly "{{ expected }}" (actual: "{{ actual }}").' ,
189
191
AtMost : 'This type is declare to have an immutability of at most "{{ expected }}" (actual: "{{ actual }}").' ,
190
192
More : 'This type is declare to have an immutability more than "{{ expected }}" (actual: "{{ actual }}").' ,
193
+ userDefined : "{{ message }}" ,
191
194
} as const ;
192
195
193
196
/**
@@ -313,7 +316,6 @@ function getConfiguredSuggestions<T extends TSESTree.Node>(
313
316
node : T ,
314
317
context : Readonly < RuleContext < keyof typeof errorMessages , RawOptions > > ,
315
318
configs : ReadonlyArray < FixerConfig > ,
316
- messageId : keyof typeof errorMessages ,
317
319
) : NonNullable < Descriptor [ "suggest" ] > | null {
318
320
const text = context . sourceCode . getText ( node ) ;
319
321
const matchingConfig = configs . filter ( ( c ) => c . pattern . test ( text ) ) ;
@@ -322,7 +324,10 @@ function getConfiguredSuggestions<T extends TSESTree.Node>(
322
324
}
323
325
return matchingConfig . map ( ( config ) => ( {
324
326
fix : ( fixer ) => fixer . replaceText ( node , text . replace ( config . pattern , config . replace ) ) ,
325
- messageId,
327
+ messageId : "userDefined" ,
328
+ data : {
329
+ message : config . message ?? `Replace with: ${ text . replace ( config . pattern , config . replace ) } ` ,
330
+ } ,
326
331
} ) ) ;
327
332
}
328
333
@@ -376,7 +381,7 @@ function getResults(
376
381
const suggest =
377
382
rule . suggestions === false || isTSInterfaceDeclaration ( node )
378
383
? null
379
- : getConfiguredSuggestions ( node . typeAnnotation , context , rule . suggestions , messageId ) ;
384
+ : getConfiguredSuggestions ( node . typeAnnotation , context , rule . suggestions ) ;
380
385
381
386
return {
382
387
context,
0 commit comments