@@ -7,23 +7,52 @@ function stripAnsi(input: string): string {
77 return input . replace ( / [ \u001B \u009B ] [ [ ( ) \] # ; ? ] * (?: [ 0 - 9 ] { 1 , 4 } (?: ; [ 0 - 9 ] { 0 , 4 } ) * ) ? [ 0 - 9 A - O R Z c f - n q r y = > < ] / g, '' ) ;
88}
99
10- function annotateFromOutput ( output : string , workingDirectory : string ) {
10+ function parseFindings ( output : string , workingDirectory : string ) {
1111 const clean = stripAnsi ( output ) ;
12- const re = / ^ ( .+ ?) : ( \d + ) : ( \d + ) \s + ( E r r o r | W a r n i n g | H i n t ) : \s + ( .* ) $ / gm;
12+ const lines = clean . split ( / \r ? \n / ) ;
13+
14+ type Finding = {
15+ severity : 'Error' | 'Warning' | 'Hint' ;
16+ message : string ;
17+ file : string ;
18+ line : number ;
19+ col : number ;
20+ } ;
21+
22+ const findings : Finding [ ] = [ ] ;
23+
24+ for ( let i = 0 ; i < lines . length ; i ++ ) {
25+ const loc = lines [ i ] . match ( / ^ ( .+ ?) : ( \d + ) : ( \d + ) $ / ) ;
26+ if ( ! loc ) continue ;
27+
28+ const [ , relFile , lineStr , colStr ] = loc ;
29+ const next = lines [ i + 1 ] || '' ;
30+ const sevLine = next . match ( / ^ \s * ( E r r o r | W a r n i n g | W a r n | H i n t ) : \s * ( .* ?) (?: \s + \( [ ^ ) ] + \) ) ? $ / ) ;
31+ if ( ! sevLine ) continue ;
1332
14- let match : RegExpExecArray | null ;
15- while ( ( match = re . exec ( clean ) ) ) {
16- const [ , relFile , lineStr , colStr , sev , message ] = match ;
33+ let sev = sevLine [ 1 ] as 'Error' | 'Warning' | 'Hint' | 'Warn' ;
34+ const message = sevLine [ 2 ] ;
35+
36+ if ( sev === 'Warn' ) sev = 'Warning' ;
1737 const filePath = path . normalize ( path . join ( workingDirectory , relFile ) ) ;
1838 const line = parseInt ( lineStr , 10 ) || 1 ;
1939 const col = parseInt ( colStr , 10 ) || 1 ;
2040
21- const props = { file : filePath , startLine : line , startColumn : col , title : 'svelte-check' as const } ;
41+ findings . push ( { severity : sev as 'Error' | 'Warning' | 'Hint' , message, file : filePath , line, col } ) ;
42+ }
2243
23- if ( sev === 'Error' ) core . error ( message , props ) ;
24- else if ( sev === 'Warning' ) core . warning ( message , props ) ;
25- else core . notice ( message , props ) ;
44+ return findings ;
45+ }
46+
47+ function annotateFromOutput ( output : string , workingDirectory : string ) {
48+ const findings = parseFindings ( output , workingDirectory ) ;
49+ for ( const f of findings ) {
50+ const props = { file : f . file , startLine : f . line , startColumn : f . col , title : 'svelte-check' as const } ;
51+ if ( f . severity === 'Error' ) core . error ( f . message , props ) ;
52+ else if ( f . severity === 'Warning' ) core . warning ( f . message , props ) ;
53+ else core . notice ( f . message , props ) ;
2654 }
55+ return findings ;
2756}
2857
2958async function run ( ) : Promise < void > {
@@ -87,11 +116,11 @@ async function run(): Promise<void> {
87116 const exitCode = await exec . exec ( npx , args , options ) ;
88117 core . info ( `svelte-check exit code: ${ exitCode } ` ) ;
89118
90- annotateFromOutput ( output + '\n' + errorOutput , workingDirectory ) ;
119+ const findings = annotateFromOutput ( output + '\n' + errorOutput , workingDirectory ) ;
91120
92- const errorCount = ( output . match ( / E r r o r : / g ) || [ ] ) . length ;
93- const warningCount = ( output . match ( / W a r n i n g : / g ) || [ ] ) . length ;
94- const hintCount = ( output . match ( / H i n t : / g ) || [ ] ) . length ;
121+ const errorCount = findings . filter ( ( f ) => f . severity === 'Error' ) . length ;
122+ const warningCount = findings . filter ( ( f ) => f . severity === 'Warning' ) . length ;
123+ const hintCount = findings . filter ( ( f ) => f . severity === 'Hint' ) . length ;
95124
96125 core . setOutput ( 'errors' , String ( errorCount ) ) ;
97126 core . setOutput ( 'warnings' , String ( warningCount ) ) ;
0 commit comments