File tree Expand file tree Collapse file tree 3 files changed +42
-1
lines changed
Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ export {
5050 formatBytes ,
5151 formatDuration ,
5252 indentLines ,
53+ pluginMetaLogFormatter ,
5354 pluralize ,
5455 pluralizeToken ,
5556 roundDecimals ,
Original file line number Diff line number Diff line change 1+ import ansis from 'ansis' ;
2+ import stringWidth from 'string-width' ;
13import {
24 MAX_DESCRIPTION_LENGTH ,
35 MAX_ISSUE_MESSAGE_LENGTH ,
@@ -146,7 +148,7 @@ export function truncateMultilineText(
146148
147149export function transformLines (
148150 text : string ,
149- fn : ( line : string ) => string ,
151+ fn : ( line : string , index : number ) => string ,
150152) : string {
151153 return text . split ( / \r ? \n / ) . map ( fn ) . join ( '\n' ) ;
152154}
@@ -164,3 +166,15 @@ export function serializeCommandWithArgs({
164166} ) : string {
165167 return [ command , ...( args ?? [ ] ) ] . join ( ' ' ) ;
166168}
169+
170+ export function pluginMetaLogFormatter (
171+ title : string ,
172+ ) : ( message : string ) => string {
173+ const prefix = ansis . blue ( `[${ title } ]` ) ;
174+ const padding = ' ' . repeat ( stringWidth ( prefix ) ) ;
175+ return message =>
176+ transformLines (
177+ message ,
178+ ( line , idx ) => `${ idx === 0 ? prefix : padding } ${ line } ` ,
179+ ) ;
180+ }
Original file line number Diff line number Diff line change 55 formatDate ,
66 formatDuration ,
77 indentLines ,
8+ pluginMetaLogFormatter ,
89 pluralize ,
910 pluralizeToken ,
1011 roundDecimals ,
@@ -269,3 +270,28 @@ describe('serializeCommandWithArgs', () => {
269270 expect ( serializeCommandWithArgs ( { command : 'ls' } ) ) . toBe ( 'ls' ) ;
270271 } ) ;
271272} ) ;
273+
274+ describe ( 'pluginMetaLogFormatter' , ( ) => {
275+ it ( 'should prefix plugin title' , ( ) => {
276+ expect ( pluginMetaLogFormatter ( 'ESLint' ) ( 'Found 42 rules in total' ) ) . toBe (
277+ `${ ansis . blue ( '[ESLint]' ) } Found 42 rules in total` ,
278+ ) ;
279+ } ) ;
280+
281+ it ( 'should align multiline message with prefix' , ( ) => {
282+ expect (
283+ ansis . strip (
284+ pluginMetaLogFormatter ( 'Coverage' ) (
285+ 'Created 3 groups:\n- Line coverage\n- Branch coverage\n- Function coverage' ,
286+ ) ,
287+ ) ,
288+ ) . toBe (
289+ `
290+ [Coverage] Created 3 groups:
291+ - Line coverage
292+ - Branch coverage
293+ - Function coverage
294+ ` . trim ( ) ,
295+ ) ;
296+ } ) ;
297+ } ) ;
You can’t perform that action at this time.
0 commit comments