@@ -17,6 +17,9 @@ export const codegen: eslint.Rule.RuleModule = {
1717 meta : { fixable : true } ,
1818 create ( context : eslint . Rule . RuleContext ) {
1919 const validate = ( ) => {
20+ const logs : string [ ] = [ ]
21+ const getMessage = ( message : string ) => ( logs . length ? [ ...logs , '\n' , message ] . join ( '\n' ) : message )
22+
2023 const sourceCode = context . sourceCode . text
2124 . split ( os . EOL )
2225 . map ( line => `${ line } ` . replace ( '// eslint-plugin-codegen:trim' , '' ) )
@@ -80,7 +83,7 @@ export const codegen: eslint.Rule.RuleModule = {
8083 if ( ! endMatch ) {
8184 const afterStartMatch = startIndex + startMatch [ 0 ] . length
8285 context . report ( {
83- message : `couldn't find end marker (expected regex ${ markers . end } )` ,
86+ message : getMessage ( `couldn't find end marker (expected regex ${ markers . end } )` ) ,
8487 loc : startMarkerLoc ,
8588 fix : fixer =>
8689 fixer . replaceTextRange (
@@ -97,7 +100,9 @@ export const codegen: eslint.Rule.RuleModule = {
97100 )
98101 if ( maybeOptions . _tag === 'Left' ) {
99102 context . report ( {
100- message : `Error parsing options. Please use inline YAML e.g. \`{someString: hello, someNumber: 123, someArray: [hi, 123, true]}\`. ${ String ( maybeOptions . left ) } ` ,
103+ message : getMessage (
104+ `Error parsing options. Please use inline YAML e.g. \`{someString: hello, someNumber: 123, someArray: [hi, 123, true]}\`. ${ String ( maybeOptions . left ) } ` ,
105+ ) ,
101106 loc : startMarkerLoc ,
102107 } )
103108 return
@@ -116,7 +121,7 @@ export const codegen: eslint.Rule.RuleModule = {
116121 const preset = presets [ opts . preset ]
117122 if ( typeof preset !== 'function' ) {
118123 context . report ( {
119- message : `Unknown preset ${ opts . preset } . Available presets: ${ Object . keys ( presets ) . join ( ', ' ) } ` ,
124+ message : getMessage ( `Unknown preset ${ opts . preset } . Available presets: ${ Object . keys ( presets ) . join ( ', ' ) } ` ) ,
120125 loc : startMarkerLoc ,
121126 } )
122127 return
@@ -130,6 +135,7 @@ export const codegen: eslint.Rule.RuleModule = {
130135 existingContent,
131136 existingContentPosition : [ range [ 0 ] , range [ 1 ] ] ,
132137 sourceCode,
138+ log : message => logs . push ( message ) ,
133139 glob : globSync as never ,
134140 fs : dependencies . fs ,
135141 path,
@@ -212,7 +218,7 @@ export const codegen: eslint.Rule.RuleModule = {
212218 )
213219
214220 if ( result . _tag === 'Left' ) {
215- context . report ( { message : result . left , loc : startMarkerLoc } )
221+ context . report ( { message : getMessage ( result . left ) , loc : startMarkerLoc } )
216222 return
217223 }
218224
@@ -226,7 +232,7 @@ export const codegen: eslint.Rule.RuleModule = {
226232 let message = `content doesn't match: ${ e as string } `
227233 if ( process . env . NODE_ENV === 'test' ) message = stripAnsi ( message )
228234 context . report ( {
229- message,
235+ message : getMessage ( message ) ,
230236 loc : { start : position ( range [ 0 ] ) , end : position ( range [ 1 ] ) } ,
231237 fix : fixer => fixer . replaceTextRange ( range , normalise ( result . right ) + os . EOL ) ,
232238 } )
0 commit comments